On Saturday 30 October 2004 13:59, Tim Green wrote:
float l = 45.4567; float d = floorf(l); std::cout << "l-d = " << l - d << std::endl;
Basically, I getting an odd value printed for l - d (it comes out as 0.456699 and not 0.4567 as expected).
"float" is not that acurate. You might have more luck with "double".
Try having a lookm at http://www.win.ua.ac.be/~jvvloet/libcff/ and http://www.swox.com/gmp/
Also, my scientific calculator has a function for dealing with fractions (much more respectable in mathematical circles than decimals, well at least in theory anyway) and writing a class to implement fractions is the kind of thing that C++ textbooks are full of (you get to do operating overloading and all sorts...) [and don't forget Python: http://pinkstuff.publication.org.uk/~neil/python/fractions/]
Cheers, Richard