Scott,

>SQLite handles rounding by running the value through the internal
>printf with the appropriate precision.  As best I can tell the
>internal printf adds half a unit at the appropriate position, then
>truncates.

Yep, truncation is a way to do it but doesn't meet layman expectations 
in many (most?) cases.  Rounding is another beast entirely.

>   Since the 3.05 isn't precisely represented (with format
>%.16f, I get "3.0499999999999998"), adding .05 doesn't do much to
>improve the situation.

Due to truncation, OK. If round() were using some "round to rearest, 
ties away from zero" setting (IEEE754r) it would always work.  But that 
isn't easy to implement portably AFAICT.

>Definitely be careful when using floating-point.  This kind of thing
>is why there are so many number types in different SQL
>implementations.

... and so many settings in IEE hardware/software.  I really look 
forward Intel decimal FP being mainstream, specially in business-likely 
code like a DB engine.  But until such baby finds its way in hardware, 
I guess we're stuck with this pesky binary thing and slow / imprecise 
conversions back and forth and 1/3 + 1/3 + 1/3 != 1.

_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to