What happened to this site? And what's that frog about?

Too many decimal places in floats

F143 - Failure Feedback Forum 

Status: resolved Severity: minor Category: Vlerq Ratcl Created: 2007-03-04 Updated: 2007-03-07

% view a:F def 2.85 | get

 2.84999990463

Is there a way to preserve just the two simple decimal places on 2.85? I'm not familiar with issues of representing floating point values, so I don't know how difficult this is. I know Tcl can handle this the way I want:

 % expr 2.85
 2.85

But you are probably not able to use Tcl at that layer in your code?

Summary

This is a limitation of 32-bit floats. Use doubles.



2007-03-04 btheado

Imported

2007-03-05 jcw

This is tricky. Vlerq uses real floats at this level - not dual objects like Tcl (and also 4 bytes vs 24). You'll get a better result with doubles (view a:D def 2.85), because they are more accurate and will probably do just the right thing. It's the float -> double conversion which introduces these errors.

2007-03-07 btheado

Using doubles works great, thanks.

Add a comment:

Tip: add empty lines between paragraphs and indent lines to prevent reformatting.

Your name or initials:  

Powered by Mavrig