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
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
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
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
' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤