LB Booster
« High-precision scientific notation »

Welcome Guest. Please Login or Register.
Feb 19th, 2018, 08:43am


Speed up Liberty BASIC programs by up to ten times!
Compile Liberty BASIC programs to compact, standalone executables!
Overcome many of Liberty BASIC's bugs and limitations!
LB Booster Resources
LB Booster documentation
LB Booster Home Page
LB Booster technical Wiki
Just BASIC forum
LB Umbrella forum
Liberty BASIC forum (the original)

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: High-precision scientific notation  (Read 42 times)
Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1340
xx High-precision scientific notation
« Thread started on: Jan 23rd, 2018, 4:21pm »

LB 4 (including 4.5.1) performs floating-point arithmetic internally with a precision of approximately 15 to 16 significant figures, which should be good enough for most applications. But, strangely, if the calculation returns a value that must be represented in scientific (exponential) notation - because it is too large or too small for fixed-point format - LB will print the result only to a precision of 8 significant figures!

For example suppose you want to calculate 123456789^-20; LB knows what the answer is to an accuracy of at least 15 digits but the best you can print (easily) is:

Code:
0.14780886e-161 

This limitation arises because, uniquely in my experience, the LB 4 implementation of the USING() function does not give you the opportunity of specifying that scientific notation should be used. This omission is fixed in LBB:

Code:
    print using ("###.###################^^^^", 123456789^-20) 

which gives:

Code:
 1.4780885631555544717E-162 

(all the digits are significant).

Here's a program for printing all the powers from +42 to -42 (only a fraction of the range that LBB is capable of):

Code:
    a = 123456789
    for n = 42 to -42 step -1
        b = a^n
        print n;tab (10); using ("###.###################^^^^",b)
    next n
    end 

Richard.
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Donate $6.99 for 50,000 Ad-Free Pageviews!


This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls