single to double conversion issue

General FreeBASIC programming questions.
Post Reply
jaskin
Posts: 62
Joined: Sep 01, 2018 20:19

single to double conversion issue

Post by jaskin »

Is this normal? I would have expected the two numbers when printed would be identical. After execution the results are:

Code: Select all

414.09        414.0899963378906

Code: Select all

dim as single s1
dim as double d1
s1 = 414.09
d1 = s1
print s1,d1
sleep
jj2007
Posts: 2326
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: single to double conversion issue

Post by jj2007 »

Yes, it's normal. Single precision is different from double precision, therefore you get rounding errors.

Try this one:

Code: Select all

dim as single s1
dim as double d1
s1 = 414.09
d1 = 414.09
print s1,d1
if d1=s1 then
	print "they are equal"
else
	print "they are NOT equal"
endif
sleep
Post Reply