Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168703
Image: ubuntu2004

Recall that languages like Matlab which use IEEE double precision cannot distinguish anything 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
it is equal to 1 1.00000000000000

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
it is less than 1 99999999999999999999/100000000000000000000

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.