Who can explain this strange behavior of typeset (-l) -En? For me it looks like 
a bug.

> echo 2^69 | bc
590295810358705651712
> /bin/ksh -c 'typeset -l -E18 x;x=$(( pow(2,69) ));echo $x'
5.90295810358705652e+20
> /bin/ksh -c 'typeset -l -E19 x;x=$(( pow(2,69) ));echo $x'
5.90295810358705652e+20
> /bin/ksh -c 'typeset -l -E20 x;x=$(( pow(2,69) ));echo $x'
5.90295810358705652e+20
> /bin/ksh -c 'typeset -l -E21 x;x=$(( pow(2,69) ));echo $x'
590295810358705652

> echo 2^70 | bc
1180591620717411303424
> /bin/ksh -c 'typeset -l -E18 x;x=$(( pow(2,70) ));echo $x'
1.1805916207174113e+21
> /bin/ksh -c 'typeset -l -E19 x;x=$(( pow(2,70) ));echo $x'
1.1805916207174113e+21
> /bin/ksh -c 'typeset -l -E20 x;x=$(( pow(2,70) ));echo $x'
1.1805916207174113e+21
> /bin/ksh -c 'typeset -l -E21 x;x=$(( pow(2,70) ));echo $x'
1.1805916207174113e+21
> /bin/ksh -c 'typeset -l -E22 x;x=$(( pow(2,70) ));echo $x'
118059162071741130

> /bin/ksh -c 'typeset -E14 x;x=$(( pow(2,69) ));echo $x'
5.9029581035871e+20
> /bin/ksh -c 'typeset -E15 x;x=$(( pow(2,69) ));echo $x'
5.90295810358706e+20
> /bin/ksh -c 'typeset -E16 x;x=$(( pow(2,69) ));echo $x'
5.90295810358706e+20
> /bin/ksh -c 'typeset -E17 x;x=$(( pow(2,69) ));echo $x'
5.90295810358706e+20
> /bin/ksh -c 'typeset -E18 x;x=$(( pow(2,69) ));echo $x'
5.90295810358706e+20
> /bin/ksh -c 'typeset -E19 x;x=$(( pow(2,69) ));echo $x'
5.90295810358706e+20
> /bin/ksh -c 'typeset -E20 x;x=$(( pow(2,69) ));echo $x'
5.90295810358706e+20
> /bin/ksh -c 'typeset -E21 x;x=$(( pow(2,69) ));echo $x'
590295810358706

> /bin/ksh -c 'typeset -E15 x;x=$(( pow(2,70) ));echo $x'
1.18059162071741e+21
[...]
> /bin/ksh -c 'typeset -E21 x;x=$(( pow(2,70) ));echo $x'
1.18059162071741e+21
> /bin/ksh -c 'typeset -E22 x;x=$(( pow(2,70) ));echo $x'
118059162071741


I wonder what the precision of variables declared with typeset -E and typeset 
-l -E is. In the above examples the significand appears to be 50 and 60 bit 
resp., for 64 and 80 bit IEEE fp format I would expect 52 and 64 bit.
>  echo $(( log2(590295810358706) ))
49.0684314306758268
>  echo $(( log2(590295810358705652) ))
59.034215715337913

from the man page:
   Arithmetic Evaluation.
       […]  Evaluations are performed using double precision floating point 
arithmetic
       or long double precision floating point for systems that provide this  
data type.

identical results for
  version         sh (AT&T Research) 93v- 2013-07-24
  version         sh (AT&T Research) 93u+ 2012-08-01
Linux, SLES11 SP2, Kernel 3.0.74-0.6.10-default



Best Regards

Axel Philipp


--
MTU Aero Engines AG
Geschaeftsfuehrung/Board of Management: Egon W. Behle, Vorsitzender/CEO; Dr. 
Rainer Martens, Michael Schreyögg, Dr. Stefan Weingartner, Reiner Winkler
Vorsitzender des Aufsichtsrats/Chairman of the Supervisory Board: Klaus 
Eberhardt
Sitz der Gesellschaft/Registered Office: Muenchen
Handelsregister/Commercial Register: Muenchen HRB 157206

Diese E-Mail sowie ihre Anhaenge enthalten MTU-eigene vertrauliche oder 
rechtlich geschuetzte Informationen.
Wenn Sie nicht der beabsichtigte Empfaenger sind, informieren Sie bitte den 
Absender und loeschen Sie diese
E-Mail sowie die Anhaenge. Das unbefugte Speichern, Kopieren oder Weiterleiten 
ist nicht gestattet.

This e-mail and any attached documents are proprietary to MTU, confidential or 
protected by law.
If you are not the intended recipient, please advise the sender and delete this 
message and its attachments.
Any unauthorised storing, copying or distribution is prohibited.
_______________________________________________
ast-users mailing list
[email protected]
http://lists.research.att.com/mailman/listinfo/ast-users

Reply via email to