[GiNaC-list] to_long() of an imaginary unit is 9

Richard B. Kreckel kreckel at in.terlu.de
Wed Apr 14 21:04:15 CEST 2021

Hi Vitaly,

On 14.04.21 13:55, Vitaly Magerya wrote:
> The result of it with GiNaC 1.7.8 (CLN 1.3.6) is:
>     $ c++ -o example example.cpp -lginac -lcln && ./example
>     Numeric: I
>     .real(): 0
>     .imag(): 1
>     .numer(): I
>     .denom(): 1
>     .numer().to_long(): 9
>     .denom().to_long(): 1
>     .to_long(): 9
> Seeing that the documentation contains this phrase:
>     Both to_int()/to_long() and to_double() discard the imaginary
>     part of complex numbers.

Hmm, the manual also says that 'to_int()' and 'to_long()' only work when
the number they are applied on
 is an exact integer.
 You should do explicit checking.

> ... I'm guessing this is not the expected behavior.

According to this comment here
it is intended.

> As a related question, is there any way to prevent parser from
> interpreting "I" as an imaginary unit? I'd like it to be just a variable.

Sorry, the constants are hard-wired in parser/parser.cpp.

Richard B. Kreckel

More information about the GiNaC-list mailing list