lettura simple

The %eps Constant in Scilab

In Scilab there's a constant you should get to know: %eps. This handy tool signifies the highest level of precision your machine can muster.

%eps

Put simply, it represents the tiniest positive amount x that, when added to 1.0, makes it different from 1.0.

The specific value depends on your computer's floating-point calculation precision and the programming language you've chosen.

Why is this important? Well, it’s a great resource if you're trying to determine exactly how accurately your computer is representing floating-point numbers. If you're crunching numbers that need the utmost precision, it's crucial to understand. For example, your computer might not distinguish between two different numbers if they’re close enough.

Let's look at a practical example.

Fire up Scilab and type %eps in the command line.

%eps

Scilab will then show you the smallest number your computer can represent in scientific notation.

2.220D-16

If the gap between two numbers is less than this tiny figure, Scilab treats them as equals.

To wrap your head around this, it helps to switch from scientific notation to standard notation.

Type in the command format(21)

format(21)

This command will show you numbers up to 21 decimal places.

Now go ahead and type %eps again on the command line.

%eps

Now you can clearly see the minuscule floating-point number that your computer can represent.

0.000000000000000222

Let's take another example.

Set up two variables with two different but very closely aligned values.

a=1
b=1+%eps

Then compare the two variables using the formula a==b

a==b

Scilab comes back with F (False) as the difference between the two numbers matches the maximum precision.

In other words, Scilab sees them as two distinct values.

ans = F

Try defining the variables this way instead

a=1
b=1+%eps/2

Now the gap between the two values is even smaller – it's half the value of %eps.

Try comparing the two variables again with (a==b)

a==b

This time Scilab responds with T (True).

The difference between the two values is now below the limit of maximum possible precision, so Scilab considers them identical.

T

So, when you're undertaking scientific analysis that demands high precision, it's wise to check that the difference between your data exceeds the value of %eps.

Failing to do so can lead to errors that build up and spread throughout your calculations, potentially throwing off the accuracy of your final result or even leading you down the wrong path.




Report a mistake or post a question




FacebookTwitterLinkedinLinkedin