|
From: Hans-Bernhard B. <HBB...@t-...> - 2012-07-06 16:52:04
|
On 06.07.2012 12:10, Simon Garfunkel wrote:
> Hi all,
> I'm using Gnuplot 4.6 patchlevel 0 on Linux x86_64
> and I get a strange result when using int() function:
> ( I see that also in previous versions)
>
> gnuplot> print 19.2/0.2
> 96.0
Your problem is not actually with int(), it's with floating point
numbers in general, and the fact that your 'print' command doesn't
display all there is to know. Try this instead:
gnuplot> print sprintf("%.16f", 19.2/0.2)
95.9999999999999858
or this:
gnuplot> print 19.2/0.2 - 96
-1.4210854715202e-014
As you see, your result is not quite as exactly equal to 96.0 as the
simple `print' command makes it out to be.
> I don't know if it is required by some other feature.
It is. The feature in question is most easily remembered like this:
In computers 10.0 times 0.1 is hardly ever 1.0
|