elisp: Numeric Conversions

 
 3.5 Numeric Conversions
 =======================
 
 To convert an integer to floating point, use the function ‘float’.
 
  -- Function: float number
      This returns NUMBER converted to floating point.  If NUMBER is
      already floating point, ‘float’ returns it unchanged.
 
    There are four functions to convert floating-point numbers to
 integers; they differ in how they round.  All accept an argument NUMBER
 and an optional argument DIVISOR.  Both arguments may be integers or
 floating-point numbers.  DIVISOR may also be ‘nil’.  If DIVISOR is ‘nil’
 or omitted, these functions convert NUMBER to an integer, or return it
 unchanged if it already is an integer.  If DIVISOR is non-‘nil’, they
 divide NUMBER by DIVISOR and convert the result to an integer.  If
 DIVISOR is zero (whether integer or floating point), Emacs signals an
 ‘arith-error’ error.
 
  -- Function: truncate number &optional divisor
      This returns NUMBER, converted to an integer by rounding towards
      zero.
 
           (truncate 1.2)
                ⇒ 1
           (truncate 1.7)
                ⇒ 1
           (truncate -1.2)
                ⇒ -1
           (truncate -1.7)
                ⇒ -1
 
  -- Function: floor number &optional divisor
      This returns NUMBER, converted to an integer by rounding downward
      (towards negative infinity).
 
      If DIVISOR is specified, this uses the kind of division operation
      that corresponds to ‘mod’, rounding downward.
 
           (floor 1.2)
                ⇒ 1
           (floor 1.7)
                ⇒ 1
           (floor -1.2)
                ⇒ -2
           (floor -1.7)
                ⇒ -2
           (floor 5.99 3)
                ⇒ 1
 
  -- Function: ceiling number &optional divisor
      This returns NUMBER, converted to an integer by rounding upward
      (towards positive infinity).
 
           (ceiling 1.2)
                ⇒ 2
           (ceiling 1.7)
                ⇒ 2
           (ceiling -1.2)
                ⇒ -1
           (ceiling -1.7)
                ⇒ -1
 
  -- Function: round number &optional divisor
      This returns NUMBER, converted to an integer by rounding towards
      the nearest integer.  Rounding a value equidistant between two
      integers returns the even integer.
 
           (round 1.2)
                ⇒ 1
           (round 1.7)
                ⇒ 2
           (round -1.2)
                ⇒ -1
           (round -1.7)
                ⇒ -2