Processing math: 100%

First time here? Check out the FAQ!

Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

answered 3 years ago

Juanjo gravatar image

A Sage real number a can be written in the form a=sm2e, where s, m and e are its sign, mantissa and exponent, given by the method .sign_mantissa_exponent. For example,

sage: a = -12.345                                                               
sage: s, m, e = a.sign_mantissa_exponent(); s, m, e                             
(-1, 6949617174986097, -49)
sage: s*m*2^e.n()                                                               
-12.3450000000000

Let us see what is x=exp(12π)=exp(12πii):

sage: x = exp(12*pi*i*i); x                                                     
cosh(12*pi) - sinh(12*pi)

We next compute the mantissa and exponent of 5+cosh(12π) and sinh(12π):

sage: (5 + cosh(12*pi)).n().sign_mantissa_exponent()                            
(1, 5894625992139550, 1)
sage: sinh(12*pi).n().sign_mantissa_exponent()                                  
(1, 5894625992139548, 1)

So SageMath gets 5+x as follows:

5+x=5+cosh(12π)sinh(12π)589462599213955021589462599213954821=22=4.

This justifies the result you get. You can repeat computations to check what happens with 6+x:

sage: (6 + cosh(12*pi)).n().sign_mantissa_exponent()
(1, 5894625992139551, 1)

Hence: 6+x=6+cosh(12π)sinh(12π)589462599213955121589462599213954821=32=6.

The problem here is that you are reaching the limits of the double precision floating point arithmetic. Just use more digits:

sage: x = exp(12*pi*i*i)                                                        
sage: R = RealField(100)                                                        
sage: R(5 + x)                                                                  
5.0000000000000000000000000000
click to hide/show revision 2
No.2 Revision

A Sage real number a can be written in the form a=sm2e, where s, m and e are its sign, mantissa and exponent, given by the method .sign_mantissa_exponent. For example,

sage: a = -12.345                                                               
sage: s, m, e = a.sign_mantissa_exponent(); s, m, e                             
(-1, 6949617174986097, -49)
sage: s*m*2^e.n()                                                               
-12.3450000000000

Let us see what is $x=\exp(-12\pi)=\exp(-12\pi\cdot $x=\exp(-12\pi)=\exp(12\pi\cdot i\cdot i)$:

sage: x = exp(12*pi*i*i); x                                                     
cosh(12*pi) - sinh(12*pi)

We next compute the mantissa and exponent of 5+cosh(12π) and sinh(12π):

sage: (5 + cosh(12*pi)).n().sign_mantissa_exponent()                            
(1, 5894625992139550, 1)
sage: sinh(12*pi).n().sign_mantissa_exponent()                                  
(1, 5894625992139548, 1)

So SageMath gets 5+x as follows:

5+x=5+cosh(12π)sinh(12π)589462599213955021589462599213954821=22=4.

This justifies the result you get. You can repeat computations to check what happens with 6+x:

sage: (6 + cosh(12*pi)).n().sign_mantissa_exponent()
(1, 5894625992139551, 1)

Hence: 6+x=6+cosh(12π)sinh(12π)589462599213955121589462599213954821=32=6.

The problem here is that you are reaching the limits of the double precision floating point arithmetic. Just use more digits:

sage: x = exp(12*pi*i*i)                                                        
sage: R = RealField(100)                                                        
sage: R(5 + x)                                                                  
5.0000000000000000000000000000
click to hide/show revision 3
No.3 Revision

A Sage real number a can be written in the form a=sm2e, where s, m and e are its sign, mantissa and exponent, given by the method .sign_mantissa_exponent. For example,

sage: a = -12.345                                                               
sage: s, m, e = a.sign_mantissa_exponent(); s, m, e                             
(-1, 6949617174986097, -49)
sage: s*m*2^e.n()                                                               
-12.3450000000000

Let us see what is x=exp(12π)=exp(12πii):

sage: x = exp(12*pi*i*i); x                                                     
cosh(12*pi) - sinh(12*pi)

We next compute the mantissa and exponent of 5+cosh(12π) and sinh(12π):

sage: (5 + cosh(12*pi)).n().sign_mantissa_exponent()                            
(1, 5894625992139550, 1)
sage: sinh(12*pi).n().sign_mantissa_exponent()                                  
(1, 5894625992139548, 1)

So SageMath gets 5+x as follows:

$$5+x=5+\cosh(12\pi)-\sinh(12\pi)\approx $$\begin{aligned}5+x&=5+\cosh(12\pi)-\sinh(12\pi) \\ &\approx 5894625992139550\cdot 2^1 - 5894625992139548\cdot 2^1=2\cdot 2=4.$$2=4.\end{aligned}$$

This justifies the result you get. You can repeat computations to check what happens with 6+x:

sage: (6 + cosh(12*pi)).n().sign_mantissa_exponent()
(1, 5894625992139551, 1)

Hence: $$6+x=6+\cosh(12\pi)-\sinh(12\pi)\approx $$\begin{aligned}6+x&=6+\cosh(12\pi)-\sinh(12\pi) \\ &\approx 5894625992139551\cdot 2^1 - 5894625992139548\cdot 2^1=3\cdot 2=6.$$2=6.\end{aligned}$$

The problem here is that you are reaching the limits of the double precision floating point arithmetic. Just use more digits:

sage: x = exp(12*pi*i*i)                                                        
sage: R = RealField(100)                                                        
sage: R(5 + x)                                                                  
5.0000000000000000000000000000