m000basic2

806 days ago by jozefl

Recall that languages like Matlab which use IEEE double precision cannot distinguish a difference between two quantities smaller than machine epsilon, which is approximately 2.2 x 10^-16. Let's see what Sage does.

x = 1 - (1e-20) if x < 1: print 'it is less than 1' elif x > 1: print 'it is greater than 1' elif x == 1: print 'it is equal to 1' x 
       

This behavior shows that when the syntax NUMBER1e-NUMBER2 is used, Sage behaves just as Matlab does. Let's see what happens when we change the syntax so that 10^-20 is in rational form.

x = 1-10^(-20) if x < 1: print 'it is less than 1' elif x > 1: print 'it is greater than 1' elif x == 1: print 'it is equal to 1' x 
       

One final note: the if statement behaves in much the same way as the while loop. As in python, elif is used in place of elseif.