[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: pos-pi or neg-pi ??
From: |
arnold |
Subject: |
Re: pos-pi or neg-pi ?? |
Date: |
Wed, 27 Apr 2022 02:54:15 -0600 |
User-agent: |
Heirloom mailx 12.5 7/5/10 |
Tom,
You are correct that atan2() itself does not have a problem.
The bug boils down to a problem applying unary minus to an uninitialized
variable:
$ ./gawk 'BEGIN { printf("%f\n", -a) }'
-0.000000
$ ./gawk -M 'BEGIN { printf("%f\n", -a) }'
0.000000
I am continuing to work on this.
Arnold
Tom Gray <tom_gray@keysight.com> wrote:
> Both of the atan2 results below are correct.
> Neither result is pi because you cannot represent pi in 64-bit floating point.
> In 64-bit floating point -0 is a different number than +0 in that the sign
> bit is set.
> Atan2 returns a result dependent on the signs of it arguments.
>
> $ gawk 'BEGIN{ OFMT = "%1.18f"; print atan2 (+0,-1);}'
> 3.141592653589793116
>
> $ gawk 'BEGIN{OFMT = "%1.18f"; print atan2 (-0,-1);}'
> -3.141592653589793116
>
> I conclude Jason is an alien troll. His social skills are still adapting to
> human norms. He must write obfuscated code due to decades of oppression in
> his homeland.
>
> Today I learned more about atan2 and floating point than I knew yesterday. I
> suppose thanks to Jason.
>
> -----Original Message-----
> From: bug-gawk <bug-gawk-bounces+tom_gray=keysight.com@gnu.org> On Behalf Of
> Jason C. Kwan via Bug reports only for gawk.
> Sent: Tuesday, April 26, 2022 2:45 PM
> To: Bug-gawk <bug-gawk@gnu.org>
> Subject: pos-pi or neg-pi ??
>
> CAUTION: This message originates from an external sender.
>
> apparently gawk can't even provide a consistent answer for a code this short :
>
> - atan2( -x , -++x )
>
>
> square-root-of-pi is frequently needed in any sort of scientific computing,
> and this sign inconsistency would indeed be rather problematic since there
> isn't any built-in auto-complex-plane-switchover that i'm aware of for
> non-GMP side of gawk .
> furthermore, e^+pi / e^-pi differs by 2-and-a-half orders of magnitude, while
> sin() and tan() (actual tangent, not atan2()) results in sign flipping. The
> only thing consistent about atan2() is its level of inconsistency.
>
> gawk -e ' BEGIN { printf("gawk -v ___=%c%s%c -%-*s :: atan2(-_,-++_) =
> %+.*f%c", ____=(__+=__+=__=!+___)^--__-\
> __^__+--__, ___, ____,
> __, ___, __^(__*=+__),
> atan2(-_,-++_), ++__+__) }'
> gawk -v ___='e' -e :: atan2(-_,-++_) = -3.1415926535897931 ———————————
> —————————————— —————————— —————————————— —————————
> gawk -Me ' BEGIN { printf("gawk -v ___=%c%s%c -%-*s :: atan2(-_,-++_) =
> %+.*f%c", ____=(__+=__+=__=!+___)^--__-\
> __^__+--__, ___, ____,
> __, ___, __^(__*=+__),
> atan2(-_,-++_), ++__+__) }'
> gawk -v ___='Me' -Me :: atan2(-_,-++_) = +3.1415926535897931
> ———————————————
>
> % gawk -Me 'BEGIN { print (atan2(-log(1),-1)), (atan2(log(1),-1)); _="";
> print atan2(-_,-++_), atan2(-!_--,--_); _=""; print atan2(-_,-++_),
> atan2(-!_--,--_) ; _=""; print atan2(-_,--_), atan2(-!_,+_)
> ,atan2(!_,--_),atan2(-!_,-_),atan2(-!_,+_) ,atan2(+"-0",+"-1") }'
> -3.14159 3.141593.14159 3.141593.14159 3.141593.14159 3.14159 3.14159 0
> 3.14159 3.14159
> % gawk -e 'BEGIN { print (atan2(-log(1),-1)), (atan2(log(1),-1)); _="";
> print atan2(-_,-++_), atan2(-!_--,--_); _=""; print atan2(-_,-++_),
> atan2(-!_--,--_) ; _=""; print atan2(-_,--_), atan2(-!_,+_)
> ,atan2(!_,--_),atan2(-!_,-_),atan2(-!_,+_) ,atan2(+"-0",+"-1") }'
> -3.14159 3.14159-3.14159 -3.14159-3.14159 -3.14159-3.14159 -3.14159 3.14159 0
> -3.14159 -3.14159