Hi!
----
While writing some regression tests I found a weired detail.
The following test script (not exactly correct, but that is not the
issue in thid case ; note that you need something like ksh93s- or better
for this)
-- snip --
function err_exit
{
print -u2 -n "\t"
print -u2 -r ${Command}[$1]: "${@:2}"
let Errors+=1
}
alias err_exit='err_exit $LINENO'
float x
float y
### snip ###
(
float m
float c
for x in 0 1 -1 -Inf +Inf NaN ; do
for y in 0 1 -1 -Inf +Inf NaN ; do
if (( y < 0.0 && y != NaN )) ; then
(( m=-abs(x) ))
else
(( m=abs(x) ))
fi
(( c=copysign( x, y ) ))
[ $c == $m ] || err_exit "(( copysign( $x, $y ) != $m ; $c ))"
done
done
)
-- snip --
results in
$ ksh test_solaris.sh
[68]: (( copysign( 1, NaN ) != 1 ; -1 ))
[68]: (( copysign( -1, NaN ) != 1 ; -1 ))
[68]: (( copysign( -Inf, NaN ) != Inf ; -Inf ))
[68]: (( copysign( Inf, NaN ) != Inf ; -Inf ))
-- snip --
I've tried a small experiment and changed
-- snip --
for y in 0 1 -1 -Inf +Inf NaN ; do
-- snip --
to
-- snip --
for y in 0 1 -1 -Inf +Inf -NaN ; do
-- snip --
...which causes the test to pass...
...however I am slightly confused about a "negative NaN" - sure, the
floating point datatype allows this since the sign occupies a seperate
bit - but is |-NaN| something valid (I think the answer should be "yes"
but I am somewhat confused that the Solaris manual pages have zero
information about this detail... ;-( ) ?
How should C99 |printf()| and the shell's "printf" builtin handle this,
e.g. should the sign be printed or not (quick test: $ ksh -c 'float x ;
x=-NaN ; printf "%f $x\n" $x' # returns "NaN NaN" and no sign of a
"sign") ?
Does the C99 standard say anything about this ?
----
Bye,
Roland
--
__ . . __
(o.\ \/ /.o) roland.mainz at nrubsig.org
\__\/\/__/ MPEG specialist, C&&JAVA&&Sun&&Unix programmer
/O /==\ O\ TEL +49 641 7950090
(;O/ \/ \O;)