bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: pos-pi or neg-pi ??


From: Andrew J. Schorr
Subject: Re: pos-pi or neg-pi ??
Date: Wed, 27 Apr 2022 11:09:00 -0400
User-agent: Mutt/1.5.21 (2010-09-15)

Hi,

Just curious -- why do you say that this relates to uninitialized variables?
I see the same after initializing a to 0:

bash-4.2$ ./gawk 'BEGIN { printf("%f\n", -a) }'
-0.000000
bash-4.2$ ./gawk -va=0 'BEGIN { printf("%f\n", -a) }'
-0.000000
bash-4.2$ ./gawk 'BEGIN { a = 0; printf("%f\n", -a) }'
-0.000000

And:
bash-4.2$ ./gawk 'BEGIN { printf("%f\n", -0) }'
-0.000000

Regards,
Andy

On Wed, Apr 27, 2022 at 02:54:15AM -0600, arnold@skeeve.com wrote:
> 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

-- 
Andrew Schorr                      e-mail: aschorr@telemetry-investments.com
Telemetry Investments, L.L.C.      phone:  917-305-1748
152 W 36th St, #402                fax:    212-425-5550
New York, NY 10018-8765



reply via email to

[Prev in Thread] Current Thread [Next in Thread]