Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

In general if x % 1 fails (for x which is real) you can try RR(x) % 1 or RR(x).frac().

Note also that %1 and .frac() are different:

sage: 0.6 % 1
-0.400000000000000
sage: (0.6).frac()
0.600000000000000

In general if x % 1 fails (for x which is real) you can try RR(x) % 1 or RR(x).frac().

Note also that %1 and .frac() are different:

sage: 0.6 sqrt(3.0) % 1
-0.400000000000000
-0.267949192431123
sage: (0.6).frac()
0.600000000000000
sqrt(3.0).frac()
0.732050807568877

I guess you want the latter.

In general if x % 1 fails (for x which is real) you can try RR(x) % 1 or RR(x).frac().

Note also that %1 and .frac() are different:

sage: sqrt(3.0) RR(sqrt(3)) % 1
-0.267949192431123
sage: sqrt(3.0).frac()
RR(sqrt(3)).frac()
0.732050807568877

I guess you want the latter.

In general if x % 1 fails (for x which is real) you can try RR(x) % 1 or RR(x).frac().

Note also that %1 and .frac() are different:

sage: RR(sqrt(3)) % 1
-0.267949192431123
sage: RR(sqrt(3)).frac()
0.732050807568877

I guess you want the latter.latter. Actually %1 is a bit weird:

sage: [RR((2*k+1)/2)%1 for k in range(10)]
[0.500000000000000, -0.500000000000000, 0.500000000000000, -0.500000000000000, 0.500000000000000, -0.500000000000000, 0.500000000000000, -0.500000000000000, 0.500000000000000, -0.500000000000000]