Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Can we trust Powerbasic math?

26 views
Skip to first unread message

Olav

unread,
Jun 17, 2010, 2:46:15 AM6/17/10
to
In the first calculation shown below both Visual Basic, my calculator and
even Windows calculator produce a result of 5 720 000 000. Also Wikipedia
claims it should be 5 720 000 000.
http://en.wikipedia.org/wiki/Scientific_notation

Is E9 and 10^9 two different worlds in Powerbasic?

FUNCTION PBMAIN () AS LONG

LOCAL a AS QUAD

a = 5.72 * 10^9 ' outputs 5 719 999 790
? a
a = 5.72E9 ' outputs 5 720 000 000
? a
? "Press a key to end the program..."
WAITKEY$

END FUNCTION


Greg Neill

unread,
Jun 17, 2010, 6:54:16 AM6/17/10
to

In the first instance you have a single precision
constant multiplied by 10^9, then the type of the
result will be converted for the assignment to a.

In the second case you have a constant 5.72E9, with
no mathematical operations, being promoted in
precision at compile time for the assignment.

In place of your first assignment statement, try
specifying an apppropriate precision for the constant:

a = 5.72# * 10^9


Olav

unread,
Jun 17, 2010, 7:23:02 AM6/17/10
to

"Greg Neill" <gnei...@MOVEsympatico.ca> skrev i melding
news:x9nSn.45862$mB7....@unlimited.newshosting.com...

Yes, thank you. You are right, but Visual Basic 2010. and calculators,
solve this in a more elegant way.

Maybe VB, and calculators, sees the value 5.72 as an integer value equal
572.You then will have:

(572 * 10^9) /100 = 5 720 000 000

VB code:
Dim a As ULong
a = 5.72 * 10 ^ 9

Console.WriteLine(a) ' outputs 5 720 000 000

--

Olav


WangoTango

unread,
Jun 17, 2010, 11:22:03 AM6/17/10
to
In article <4c1a059e$1...@proxy.mimer.no>, bla..ah@assdasd.nn says...
I think you are confusing the ability to control the precision of your
data as a short coming. I know it is BASIC, but come on.
>
> Maybe VB, and calculators, sees the value 5.72 as an integer value equal
> 572.You then will have:
Fixed point math is common, but I doubt VB would use it. More likely
they default to the highest precision. All of this should be something
found in the documentation of the compiler, including the PowerBASIC
"problem".

hutch--

unread,
Jun 18, 2010, 4:38:01 AM6/18/10
to
Pick your precision level.

Results

1 integer
5719999790
5720000000

2 extended
5719999790.19165039
5720000000

3 double
5719999790.19165039
5720000000

4 single
5720000000
5720000000

code

' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

FUNCTION PBmain as LONG

LOCAL a AS QUAD

LOCAL x as EXT
LOCAL y as DOUBLE
LOCAL z as SINGLE

StdOut chr$(13,10)+"1 integer"


a = 5.72 * 10^9 ' outputs 5 719 999 790
? a
a = 5.72E9 ' outputs 5 720 000 000
? a

StdOut chr$(13,10)+"2 extended"
x = 5.72 * 10^9
StdOut str$(x,24)
x = 5.72E9
StdOut str$(x,24)

StdOut chr$(13,10)+"3 double"
y = 5.72 * 10^9
StdOut str$(y,24)
y = 5.72E9
StdOut str$(y,24)

StdOut chr$(13,10)+"4 single"
z = 5.72 * 10^9
StdOut str$(z,24)
z = 5.72E9
StdOut str$(z,24)

Do
Sleep 1
Loop while inkey$ = ""

FUNCTION = 0

End FUNCTION

' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

0 new messages