Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

A Sage real number $a$ can be written in the form $a=s\cdot m\cdot 2^e$, 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 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\pi)$ and $\sinh(12\pi)$:

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 5894625992139550\cdot 2^1 - 5894625992139548\cdot 2^1=2\cdot 2=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\pi)-\sinh(12\pi)\approx 5894625992139551\cdot 2^1 - 5894625992139548\cdot 2^1=3\cdot 2=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

A Sage real number $a$ can be written in the form $a=s\cdot m\cdot 2^e$, 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\pi)$ and $\sinh(12\pi)$:

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 5894625992139550\cdot 2^1 - 5894625992139548\cdot 2^1=2\cdot 2=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\pi)-\sinh(12\pi)\approx 5894625992139551\cdot 2^1 - 5894625992139548\cdot 2^1=3\cdot 2=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

A Sage real number $a$ can be written in the form $a=s\cdot m\cdot 2^e$, 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 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\pi)$ and $\sinh(12\pi)$:

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