Just wondering why both PB and Blitz return floats on something like:
2 ^ 24 ' Blitz
or
Pow(2,24) ; PB
BTW, PB returns the CORRECT integer portion (even though the answer is strangely a float), whereas Blitz does not.
What makes this strange to me is that it is mathematically impossible for an integer taken to the power of an integer to return a fractional result, yet both PB and Blitz do (and probably others as well, haven't checked).
Russell
p.s. Speaking of math, this could be a useful math library to incorporate into PB: http://www.tc.umn.edu/~ringx004/mapm-main.html
What's so great about this library you say? Whereas PB allows up to a dozen and a half or so digits of precision, the MAPM lib allows up to (get this):
BILLIONS of digits! (An extreme example, I know)
Now, you might be thinking "Well, that would probably take a looooooong time to process!". And you'd be right in this most extreme example, but not as long as you might think. Using smart 'FFT' (Fast Fourier Transform) and other tricks, the time can be greatly slashed.
Why does Pow() require and return floats?
Why does Pow() require and return floats?
*** Diapers and politicians need to be changed...for the same reason! ***
*** Make every vote equal: Abolish the Electoral College ***
*** www.au.org ***
*** Make every vote equal: Abolish the Electoral College ***
*** www.au.org ***
-
DarkDragon
- Addict

- Posts: 2347
- Joined: Mon Jun 02, 2003 9:16 am
- Location: Germany
- Contact:
- Michael Vogel
- Addict

- Posts: 2820
- Joined: Thu Feb 09, 2006 11:27 pm
- Contact:
Re: Why does Pow() require and return floats?
1<<24Amiga5k wrote:Just wondering why both PB and Blitz return floats on something like:
2 ^ 24 ' Blitz
or
Pow(2,24) ; PB
DarkDragon, I'm not sure I follow you. Can you explain what you mean when you say 'everything else is incorrect'?
Russell
Russell
*** Diapers and politicians need to be changed...for the same reason! ***
*** Make every vote equal: Abolish the Electoral College ***
*** www.au.org ***
*** Make every vote equal: Abolish the Electoral College ***
*** www.au.org ***
-
DarkDragon
- Addict

- Posts: 2347
- Joined: Mon Jun 02, 2003 9:16 am
- Location: Germany
- Contact:
Ah, but it returns a float even if the result should be an integer!
(But at least PB returns the correct answer, unlike BlitzMax...). The point is that it would be nice if there were two versions of Pow(): One Integer, one Float. Yes, it can be done.
In my example, PB returned 16777216.0 (correct) and BMax returned...Hmm. That's interesting: I just tried it in BMax. If I run 'Print 2 ^ 24' I get 16777216.000000000 (which is correct). But If I run:
..the answer for 2 ^ 24 becomes 16777215.999999976 for some odd reason (incorrect). I wonder why there are two different outcomes for the same expression? I'll have to run this one by the Blitz forums...
Russell
In my example, PB returned 16777216.0 (correct) and BMax returned...Hmm. That's interesting: I just tried it in BMax. If I run 'Print 2 ^ 24' I get 16777216.000000000 (which is correct). But If I run:
Code: Select all
For a = 0 To 31
Print 2 ^ a
Next
Russell
*** Diapers and politicians need to be changed...for the same reason! ***
*** Make every vote equal: Abolish the Electoral College ***
*** www.au.org ***
*** Make every vote equal: Abolish the Electoral College ***
*** www.au.org ***
And what about 'Doubles' and 'Quads' ?Amiga5k wrote:The point is that it would be nice if there were two versions of Pow(): One Integer, one Float. Yes, it can be done.
Just like Val(), ValF(), ValD(), ValQ()...
It might be good to have Pow(), PowF(), PowD(), PowQ()... but maybe i'm wrong :roll:
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
-
dracflamloc
- Addict

- Posts: 1648
- Joined: Mon Sep 20, 2004 3:52 pm
- Contact:
