Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Rational numbers operation



tartifola@xxxxxxxxx wrote:
> a newbie question on operations with rational numbers with the zshell.
> If I try from the shell
> 
> >echo $((100.5 * 0.001 )) 
> 
> I got the correct result without any error. On the contrary if I try the same
>  thing in script I get this error
> 
>  syntax error: invalid arithmetic operator (error token is ".5 * 0.001 ")
> 
> I'm sure I'm missing something very basic, any hints?

The script is running under bash, not zsh.  Bash (up to 3.x, anyway)
doesn't support floating point in that expression and gives you the
error you're seeing.  Make sure you've got the #!/bin/zsh (or whatever)
line atthe start of the script right.

(You shouldn't have to load anything special, however, arithmetic
expansion is a basic part of the shell.)

-- 
Peter Stephenson <pws@xxxxxxx>            Software Engineer
Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom



Messages sorted by: Reverse Date, Date, Thread, Author