Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Euler's identity in Raku

by syphilis (Archbishop)
on Jun 03, 2021 at 05:27 UTC ( #11133458=note: print w/replies, xml ) Need Help??


in reply to Euler's identity in Raku

Why is the fancy part not 0?

Because the estimation used for "pi" is not exactly equal to pi.
For the imaginary part of the result to be zero, you need to multiply "i" by exactly pi.

Cheers,
Rob

Replies are listed 'Best First'.
Re^2: Euler's identity in Raku
by tomasz (Acolyte) on Jun 03, 2021 at 05:41 UTC
    Wouldn't e have to be pure also?
      Wouldn't e have to be pure also?

      You're correct - the inexactness of "e" is also influencing the result.


      UPDATE: BTW, in perl we can reproduce you're original result with:
      >perl -MMath::Complex -le "print exp(1) ** (pi * i);" -1+1.22460635382238e-16i
      Oops ... hang on ... that's not exactly the same. (I'm not all that familiar with Raku, so I'm not sure what accounts for that difference.)

      Cheers,
      Rob

        Copying Rob's one-liner into my system gives yet another answer:

        -1+1.22464679914735e-16i
        

        Using perl -v, my perl is "

        This is perl 5, version 32, subversion 1 (v5.32.1) built for x86_64-linux-gnu-thread-multi
        
        ". Possibly different compilers or options used to build the executables. As somebody who has dealt with floating point issues, 10**(-16) in a operation return like this is frequently noise. I'd not expect perl to return exactly zero to sin(pi) and I don't get it, but 1.22464679914735e-16.

        That's hinting at something, but I'm not quite sure what.

        Tried (and hopefully succeeded) in fixing the formatting, so my reply isn't in my sig.


        Information about American English usage here and here. Floating point issues? Please read this before posting. — emc

A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11133458]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2023-02-06 22:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer not to run the latest version of Perl because:







    Results (37 votes). Check out past polls.

    Notices?