Subject: Re: floating point negative zero in awk
To: None <tech-userlevel@NetBSD.org>
From: ITOH Yasufumi <itohy@NetBSD.org>
List: tech-userlevel
Date: 08/29/2007 21:53:08
apb@cequrux.com writes:
> Of the tools supplied with NetBSD that are capable of performing
> arbitrary arithmetic, awk seems to be the only one that prints
> negative zero as the result from simple calculations:
> 
> 	$ echo $(( -1 * 0 ))
> 	0
> 	$ expr -1 \* 0
> 	0
> 	$ echo '-1.0 * 0.0' | bc
> 	0
> 	$ echo '-1.0 0.0 * p' | dc
> 	0
> 	$ echo | awk '{ print -1 * 0 }'
> 	-0

	% uname -srm
	SunOS 5.8 sun4u
	% awk 'BEGIN {print -1 * 0}' </dev/null
	-0
	% nawk 'BEGIN {print -1 * 0}' </dev/null
	-0
	% echo '_1 0 * p' | dc
	0
	% echo '-1 * 0' | bc
	0
	% expr -1 \* 0
	0
	% which awk nawk dc bc expr
	/usr/bin/awk
	/usr/bin/nawk
	/usr/bin/dc
	/usr/bin/bc
	/usr/bin/expr
	%

	% uname -sr
	HP-UX B.11.00
	% awk 'BEGIN {print -1 * 0}' </dev/null
	-0
	% echo '_1 0 * p' | dc
	0
	% echo '-1 * 0' | bc
	0
	% expr -1 \* 0
	0
	% which awk dc bc expr
	/usr/bin/awk
	/usr/bin/dc
	/usr/bin/bc
	/usr/bin/expr
	%

Just for your information.
-- 
ITOH Yasufumi