Problem with powers

BlitzMax Forums/BlitzMax Programming/Problem with powers

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

No, it's not a bug with print. 4.0^2.0 returns a double. By doing x:float = 4.0 ^ 2.0, you are casting the double to a lower precision float, which happens to truncate the inacurate bits. When you Print x^2.0, it is printing the entire Double result. Try casting the result to float like this
x:Float = 4.0
Print Float(x^2.0)

It now prints 16.

The problem is with the ^ opperator itself. It doesn't distinguish the different types of variables passed to it, treating them all like doubles. Then after some checks for range and negatives, it passes the parameters into the Log() and Exp() functions which take Doubles as parameters. This will always create precision problems like with any floating point numbers.