On 3 September 2013 15:22, Glenn Fowler <[email protected]> wrote: > > On Tue, 3 Sep 2013 04:35:56 +0200 Tina Harriott wrote: >> 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 > > 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: [email protected] _______________________________________________ ast-developers mailing list [email protected] http://lists.research.att.com/mailman/listinfo/ast-developers
