On 4/1/11 2:17 PM, ObsessiveMathsFreak wrote:
Thanks for that, but I've run into another issue. I don't know whether
this is related to the sequence syntax or not
sage: for n in [0.0,0.1,..,1.1]:
sage: print n, floor(n)
0.000000000000000 0
0.100000000000000 0
0.200000000000000 0
0.300000000000000 0
0.400000000000000 0
0.500000000000000 0
0.600000000000000 0
0.700000000000000 0
0.800000000000000 0
0.900000000000000 0
1.00000000000000 0<----- What's going on here?
1.10000000000000 1
I realise that the numbers are floating point and so on, but something
appears to have gone awry here in a big way
You've answered your own question here:
sage: a=[0.0,0.1,..,1.1]
sage: a[-2]
1.00000000000000
sage: a[-2]==1
False
sage: a[-2]-1
-1.11022302462516e-16
sage: a[-2]<1
True
sage: b=a[-2]
sage: b.str(truncate=False) # don't round
'0.99999999999999989'
If you want exact values and don't want to deal with messy floating
point issues, then you can use exact values:
sage: a=[0,1/10,..,11/10]
sage: a
[0, 1/10, 1/5, 3/10, 2/5, 1/2, 3/5, 7/10, 4/5, 9/10, 1, 11/10]
sage: a[-2]==1
True
Jason
--
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org