[erlang-questions] math ceil floor

Richard A. O'Keefe ok@REDACTED
Fri Jun 3 05:36:16 CEST 2016



On 3/06/16 10:42 AM, Technion wrote:
>
> Following from other languages, C's ceil returns floats, but Ruby's 
> ceil returns an Integer, PHP returns a float.
>
>
> I'm seeing here there isn't a particularly accepted standard.
>

Let's put that another way.
C's library is defective in only offering truncation to integer (via (int))
and rounding (via l[l]rint{f,,l}()), no int-valued floor or ceiling.
Ruby's Float class is defective in only offering conversion to integer,
not float-valued ceiling &c (Float.round can be persuaded to return a
float, but not when you want it to be integral, which is both absurd and
painfully typical of Ruby).
PHP is, well, PHP.

If, on the other hand, we turn to other languages,
we learn that Lisp has {f,}(round,floor,ceiling,truncate)
and ML has realFloor, realCeil, realTrunc, realRound and
floor, ceil, trunc, round, 8 functions, not 4.
(The REAL signature, section 11.50 of The Standard
ML Basis Library.)

So there is prior art for providing *both*, with the simple name
delivering an integer, and the prefixed name returning float.




More information about the erlang-questions mailing list