Back

IEEE-remainder (clj)

(source)

function

(IEEE-remainder dividend divisor)
Returns the remainder per IEEE 754 such that remainder = dividend - divisor * n where n is the integer closest to the exact value of dividend / divisor. If two integers are equally close, then n is the even one. If the remainder is zero, sign will match dividend. If dividend or divisor is ##NaN, or dividend is ##Inf or ##-Inf, or divisor is zero => ##NaN If dividend is finite and divisor is infinite => dividend See: https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html#IEEEremainder-double-double-

Examples

clojure
(ns clojure.test-clojure.math
  (:require
    [clojure.test :refer :all]
    [clojure.math :as m]))

(deftest test-IEEE-remainder
  (is (NaN? (m/IEEE-remainder ##NaN 1.0)))
  (is (NaN? (m/IEEE-remainder 1.0 ##NaN)))
  (is (NaN? (m/IEEE-remainder ##Inf 2.0)))
  (is (NaN? (m/IEEE-remainder ##-Inf 2.0)))
  (is (NaN? (m/IEEE-remainder 2 0.0)))
  (is (= 1.0 (m/IEEE-remainder 5.0 4.0))))