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

Re: why do ceil/floor give the decimal dot?



On May 14,  5:29am, Emanuel Berg wrote:
}
}     prefix-len () {
}         local hosts=$1
}         echo $(( 32 - int(ceil(log($hosts)/log(2))) ))
}     }
} 
} without the integer conversion, the output for
} 
}     prefix-len 30
} 
} isn't 27, but "27."

Yes, because as in most languages all integers in a mixed-type expression
are converted to floating point before the operation is carried out, so
$(( 32 - anyfloat )) becomes $(( 32. - anyfloat )) and results in a float.

If what you want to argue is that floating point values that happen to be
whole numbers should not print the trailing dot, that's another discussion.



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