Subject: Re: floating point negative zero in awk
To: Jason Thorpe <thorpej@shagadelic.org>
From: Aleksey Cheusov <cheusov@tut.by>
List: tech-userlevel
Date: 09/08/2007 10:48:52
> On Aug 27, 2007, at 7:53 PM, Jeremy C. Reed wrote:
>> On Mon, 27 Aug 2007, Jason Thorpe wrote:
>>
>>>> $ echo | awk '{ print -1 * 0 }'
>>>> -0
>>>>
>>>> Would it be OK if I commit the following patch, which ensures that
>>>> arithmetic in awk will never yield a negative zero?
>>>
>>> No objection from me. Does POSIX have anything to say about this?
>>> What does
>>> GNU AWK do?
>>
>> glacier:/opt/home/reed/book/bsdwiki$ echo | awk '{ print -1 * 0 }'
>> -0
>>
>> glacier:/opt/home/reed/book/bsdwiki$ echo | gawk '{ print -1 * 0 }'
>> 0
> Then your patch is fine with me.
JFYI
~>gawk 'BEGIN { print (-1) * 0 }'
0
~>gawk 'BEGIN { printf "%d\n", (-1) * 0 }'
0
~>gawk 'BEGIN { printf "%g\n", (-1.0) * 0.0 }'
-0
~>
--
Best regards, Aleksey Cheusov.