Float Bug or Head Bug?

BlitzMax Forums/BlitzMax Programming/Float Bug or Head Bug?

Ok, not sure if this is me or not but this seems to be a bit of an oddity with float.

while debugging a bit of code to fade in and out text.

i came a cross too large a number for what I had added


here is an example
SuperStrict

Local floaty : Float = 0


For Local x : Int = 0 To 10

	floaty :+ Float(0.05)
	Print floaty

Next


as you see i'm adding 0.05 the floaty (set to zero) i would expect this to increment in the following way

0, 0.05, 0.10, 0.15.... etcertera

this is what happens

Building untitled2
Compiling:untitled2.bmx
flat assembler  version 1.64
3 passes, 2725 bytes.
Linking:untitled2.debug.exe
Executing:untitled2.debug.exe
0.0500000007
0.100000001
0.150000006
0.200000003
0.250000000
0.300000012
0.350000024
0.400000036
0.450000048
0.500000060
0.550000072

Process complete


the number is very slightly larger than it should be, why is this?

cheers.

Float point inaccuracy. There are quite a few threads explaining why
this occurs but, apparently, it's to be expected.

thanks, I did do a search on this but did not come up with much :(

cheers.

Can someone post a link with an explanation?

Inaccurate Floating Point

Thanks for the link. Haven't come from my search.
This is another link that is intersting reading.
IEEE Floating Point Standard