[geeks] expr and math

Phil Stracchino alaric at caerllewys.net
Tue Sep 21 11:42:17 CDT 2004


On Tue, Sep 21, 2004 at 04:00:48AM -0500, Brian Dunbar wrote:
> I need to do a bit of math on some data in ascii format.  Hey, sez I, 
> the expr function can handle that.  The results was getting strange on 
> me, however .. what's going on here?
> 
> briandunbar_natasha_~:expr 90 \* 100
> 9000
> briandunbar_natasha_~:expr 90 \* 1000
> 90000
> briandunbar_natasha_~:expr 90 \* 10000
> 900000
> briandunbar_natasha_~:expr 90 \* 100000
> 9000000
> briandunbar_natasha_~:expr 90 \* 1000000
> 90000000
> briandunbar_natasha_~:expr 90 \* 10000000
> 900000000
> briandunbar_natasha_~:expr 90 \* 100000000
> 410065408
> briandunbar_natasha_~:expr 90 \* 1000000000
> -194313216
> 
> I barely escaped Rube Junction High School with a C average, but even I 
> know in the real world 90 X 100000000 isn't '410065408'
> 
> What gives?


I'd guess an integer overflow problem somewhere inside expr.  Tried
piping it to bc instead?

babylon5:alaric:~:3 $ echo 90 \* 1000000000 |bc
90000000000


-- 
  ========== Fight Back!  It may not be just YOUR life at risk. ==========
  alaric at caerllewys.net : phil-stracchino at earthlink.net : phil at novylen.net
   phil stracchino : unix ronin : renaissance man : mystic zen biker geek
     2000 CBR929RR, 1991 VFR750F3 (foully murdered), 1986 VF500F (sold)
           Linux Now!  ...Friends don't let friends use Microsoft.



More information about the geeks mailing list