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

Re: Math expression evaluation error?



On 01/09/2015 04:25 PM, Bart Schaefer wrote:
On Fri, Jan 9, 2015 at 3:52 PM, Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
It seems to me that if the
shell accepts the fractions then it should return the correct answer.  I'd
make integer math  the option and have accurate results as the default
but that's just me.

3/8 is not a fraction.  Yes, in a text paragraph like this one I might
write 3/8 as a fraction because I can't write a superscript three over
a subscript eight, but in an arithmetic expression 0.375 is a fraction
and 3/8 is "integer 3 divided by integer 8", and the definition of
"divided by" includes "if both numerator and denominator are integers,
then the result must also be an integer".  As has been mentioned, this
is the way a LOT of programming languages work.
Well, this is one of those things that won't change, but I must say that in my experience an overwhelming majority of people would say that 3/8 is a fraction, and they would be surprised that in zsh, by default :

1/2 + 1/2 = 0

And I'll bet they'd wonder why even though zsh is quite capable of doing floating point math, it chooses to behave like an abacus by default, other programing languages notwithstanding. Never mind, I'll just 'setopt force_float' and have accuracy. I'm glad I was forewarned about this, however.




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