Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Re: How to get better exponentiation?by syphilis (Archbishop) |
on Jan 23, 2022 at 01:15 UTC ( [id://11140731]=note: print w/replies, xml ) | Need Help?? |
So, what’s the quickest/simplest/correct way to get Perl to act like the calculator app that comes with Windows, and give -2 as the cube root of -8? Update: The below is based upon my observations of the Windows calculator on Windows 7. Some further reading indicates that things might be different on Windows 10. I think that the calculator app, when calculating x ** y for x < 0 proceeds roughly as follows: As you can see, in addition to needing an exponentiation function, that method also requires a function that calculates the nth root. If you use that method and make use of POSIX::cbrt(), you should see that it DWYMs for the case -8 ** (1 / 3) It might also be that the windows calculator is performing decimal arithmetic - and that could also produce results that differ slightly from perl in some cases. Does anyone know for sure the number base that's used by the windows calculator ? Cheers, Rob
In Section
Seekers of Perl Wisdom
|
|