I've just noticed something strange with real number arithmetic in ksh.
The problem:
It seems that the fractional part in a division is interpreted as integer.
$ print $(( log(2.171828) ))
0.775569209249095711
$ print $(( log(2000000.0) / log(2.171828) ))
ksh: log(2000000.0) / log(2.171828) : divide by zero
$ print $(( log(2000000.0) / log(2) ))
ksh: log(2000000.0) / log(2) : divide by zero
$ print $(( log(2000000.0) / log(3) ))
14
$ typeset -F a=2000000
$ typeset -F b=2.71828
$ print $(( log(a) / log(b) ))
ksh: log(a) / log(b) : divide by zero
$ print $a $b
2000000.0000000000 2.7182800000
$ typeset -F b=3.0
$ print $(( log(a) / log(b) ))
14
$ printf "%f\n" $(( log(a) / log(b) ))
14.000000
$ typeset -F b=3.1
$ printf "%f\n" $(( log(a) / log(b) ))
14.000000
$ ksh --version
version sh (AT&T Research) 93t+ 2010-03-05
All done in the LC_ALL=C locale. On a Linux 2.6 platform.
Am I doing something wrong or is this some shell issue?
Thanks!
_______________________________________________
ast-users mailing list
[email protected]
http://lists.research.att.com/mailman/listinfo/ast-users