Image Map Image Map
Results 1 to 5 of 5

Thread: Newton's method in QBASIC

  1. #1
    Join Date
    Jun 2020
    Location
    Tennessee, USA
    Posts
    21

    Default Newton's method in QBASIC

    Some talk about the speed of math functions in Commodore BASIC in another thread inspired me to write a quick-and-dirty implementation of the calculus concept of Newton's method in QBASIC as a sort of benchmark for DOS PCs this morning. If you're not familiar, Newton's method is an algorithmic method for estimating zeroes (where a graph crosses the x-axis), and requires a guess as to where this occurs. The definition of this method is:

    xn+1=xn-(f(xn)/f'(xn))

    where f(x) is the function you wish to find the zero of, xn is the current guess, xn+1 is the calculated next guess, and f'(x) is the derivative of f(x).

    Feel free to try it out and report back. This is by no means a good example of BASIC or QBASIC code and could probably use some optimization and cleanup, I only wrote this in about an hour or so. Everything uses double-precision internally to prevent precision loss so I'd be interested in particular to see the differences with and without an FPU installed.

    Full disclosure, I wrote this in Windows 98 so I don't know how well this will run on a pre-286. YMMV. Feel free to direct me to another forum category if QBASIC doesn't run on a < 386.
    Attached Files Attached Files

  2. #2
    Join Date
    Aug 2006
    Location
    Chicagoland, Illinois, USA
    Posts
    6,537
    Blog Entries
    1

    Default

    A couple of random responses:

    - This does more to benchmark BASIC implementations than it does to benchmark a system, unless you specify exactly which qbasic interpreter or compiler you wrote it for
    - QBASIC runs on every system
    - The version of QBASIC that comes with DOS 6 doesn't use floating-point IIRC -- I thought that was only a feature of the compilers, but I could be wrong
    Offering a bounty for:
    - A working Sanyo MBC-775, Olivetti M24, or Logabax 1600
    - Music Construction Set, IBM Music Feature edition (has red sticker on front stating IBM Music Feature)

  3. #3
    Join Date
    May 2009
    Location
    Connecticut
    Posts
    4,718
    Blog Entries
    1

    Default

    QBASIC supports floating point. It does not support math coprocessors though which was reserved for the compilers.

  4. #4
    Join Date
    Jun 2020
    Location
    Tennessee, USA
    Posts
    21

    Default

    [quote Trixter]This does more to benchmark BASIC implementations than it does to benchmark a system, unless you specify exactly which qbasic interpreter or compiler you wrote it for[/quote]

    Yeah, I guess that's what I meant. Sorry for the confusion.

    [quote Trixter]QBASIC runs on every system
    - The version of QBASIC that comes with DOS 6 doesn't use floating-point IIRC -- I thought that was only a feature of the compilers, but I could be wrong[/quote]

    I didn't know QBASIC ran on everything, but the QBASIC that comes with DOS 6 definitely does use floating point, that's what I wrote it on.

    [quote krebizfan]It does not support math coprocessors though which was reserved for the compilers.[/quote]

    That I didn't know, but it does make sense I suppose. I have a copy of Borland C++ that hasn't seen some attention here recently, I might just fire it up and write an implementation in that and compile it specifically for benchmarking FPUs.

  5. #5
    Join Date
    Aug 2006
    Location
    Chicagoland, Illinois, USA
    Posts
    6,537
    Blog Entries
    1

    Default

    Quote Originally Posted by nkeck72 View Post
    I didn't know QBASIC ran on everything, but the QBASIC that comes with DOS 6 definitely does use floating point, that's what I wrote it on.
    Apologies to you and krebizfan; I meant that it doesn't support the 8087 math co-processor unless you're using a compiler, as krebizfan confirmed. All versions of Microsoft BASIC in all forms support floating-point routines.
    Offering a bounty for:
    - A working Sanyo MBC-775, Olivetti M24, or Logabax 1600
    - Music Construction Set, IBM Music Feature edition (has red sticker on front stating IBM Music Feature)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •