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

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



Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> writes:

> 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.

You mean like this?

    $ printf "%d\n" $(( 7.5 + 0.5 ))
    8

No, I don't care what data type is used as long as

    1. ceil and floor return integers in the math
       sense (otherwise the function I just posted is
       is incorrect); and

    2. when the result is printed, it is printed as
       x (and not "x.") for an integer x, because
       otherwise I can't use that function in scripts
       and functions without removing the dot
       each time.

Or, do you think the "unbroken chain of floats"/"the
shell will deal with it"-approach instead should be
put to use, i.e. rolling with the punches, e.g.

    $ g () { return 6.0 }; g; b=$?; printf "%d\n" $b
    6

Is that what you are saying?

-- 
underground experts united
http://user.it.uu.se/~embe8573



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