Float mantissa, negative integer exponent

Discussion about the ZBasic language including the System Library. If you're not sure where to post your message, do it here. However, do not make test posts here; that's the purpose of the Sandbox.
Post Reply
GTBecker
Posts: 616
Joined: 17 January 2006, 19:59 PM
Location: Cape Coral

Float mantissa, negative integer exponent

Post by GTBecker »

Code: Select all

console.writeline(cstr((10.0^2.0)))  ' yields 100.0
console.writeline(cstr((10.0^-2.0))) ' yields 10.0E-3 = 0.01
console.writeline(cstr((10^2)))      ' yields 100
console.writeline(cstr((10^-2)))     ' yields 0 since cint(0.01)=0
console.writeline(cstr((10.0^2)))    ' yields 100.0
console.writeline(cstr((10.0^-2)))   ' yields &.& ?
Tom
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Re: Float mantissa, negative integer exponent

Post by dkinzer »

GTBecker wrote:

Code: Select all

console.writeline(cstr((10.0^-2)))   ' yields &.& ?
This occurs because integral constants are represented internally as unsigned 32-bit values so the effect is the same as 10.0 ^ &Hfffffffe. The fact that the negative sign is present is stored along with the constant so this probably can be made to work as you were expecting it to work.

In the mean time, you can force the desired behavior by making it clear that you want the exponent treated as a signed value, e.g.

Code: Select all

console.writeline(cstr((10.0^CInt(-2))))
- Don Kinzer
Post Reply