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

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



On May 14, 11:12am, Emanuel Berg wrote:
} Subject: 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 mean that looking at this:

torch% float X=27
torch% print $X
2.700000000e+01
torch% print $(( X ))
27.
torch% printf "%f\n" $X        
27.000000
torch% printf "%g\n" $X
27

One might wonder why there are four different representations of the
same number, and we could therefore discuss whether some of them should
be unified.  This is not the same discussion as whether they should be
converted to integers.

I don't imagine we have much leeway with printf, but ksh uses the "%g"
style for each of the first two cases instead of using scientific or
decimal notation.  I don't recall why zsh chose the other formats.

The problem changing the output reprsentations is that it potentially
changes the interpretation of $(( $X )) to be different from $(( X )).



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