Discussion:
[ast-developers] arithmetric function int() does not work
Tina Harriott
2013-09-03 02:35:56 UTC
Permalink
The arithmetic function int() does not work in sh (AT&T Research) 93v-
2013-08-27

I get this:
ksh -c 'print -- $(( log2( int(pow(2,69) )) ))'
69

But it should print 'nan', as it does if I use explicitly an
intermediate integer variable:
ksh -c 'integer i; print -- $(( i=pow(2,69) , log2(i) ))'
nan

Tina
--
Tina Harriott - Women in Mathematics
Contact: tina.harriott.math at gmail.com
Glenn Fowler
2013-09-03 13:22:12 UTC
Permalink
Post by Tina Harriott
The arithmetic function int() does not work in sh (AT&T Research) 93v-
2013-08-27
ksh -c 'print -- $(( log2( int(pow(2,69) )) ))'
69
But it should print 'nan', as it does if I use explicitly an
ksh -c 'integer i; print -- $(( i=pow(2,69) , log2(i) ))'
nan
in ksh93 the int() arith function is an alias for the shell floor()
which calls the C library floorl() (or floor() if long double not available)
C floor() has no "too big to fit in C integral value" error

if int(f) is supposed to act like the C cast (int)f then the ksh int() needs to
be its own function that implements the cast (ksh_int_type)f
Tina Harriott
2013-09-04 16:37:36 UTC
Permalink
Post by Glenn Fowler
Post by Tina Harriott
The arithmetic function int() does not work in sh (AT&T Research) 93v-
2013-08-27
ksh -c 'print -- $(( log2( int(pow(2,69) )) ))'
69
But it should print 'nan', as it does if I use explicitly an
ksh -c 'integer i; print -- $(( i=pow(2,69) , log2(i) ))'
nan
in ksh93 the int() arith function is an alias for the shell floor()
which calls the C library floorl() (or floor() if long double not available)
C floor() has no "too big to fit in C integral value" error
if int(f) is supposed to act like the C cast (int)f then the ksh int() needs to
be its own function that implements the cast (ksh_int_type)f
int() like C++ int() may be more intuitive. I haven't found any
mapping table shell arithmetic function name->C function name so I
assumed it works like C/C++.

Coincidentally there is no float() function to turn an integer into
ksh's equivalent of a long double. The purpose would be to promote the
variables type to a long double (typeset -lE) so that integer x=1;
$((float(x)/3)) yields 0.33333333333333333333333333333

Tina
--
Tina Harriott - Women in Mathematics
Contact: tina.harriott.math at gmail.com
David Korn
2013-09-04 19:14:58 UTC
Permalink
cc: ast-developers at research.att.com ast-users at lists.research.att.com
Subject: Re: Re: [ast-developers] arithmetric function int() does not work
--------
Post by Tina Harriott
Coincidentally there is no float() function to turn an integer into
ksh's equivalent of a long double. The purpose would be to promote the
variables type to a long double (typeset -lE) so that integer x=1;
$((float(x)/3)) yields 0.33333333333333333333333333333
Tina
--
You can do
$((x/3.))
which will convert x to floating point and then do the division.

David Korn
dgk at research.att.com

Loading...