1.3.0 permalink Arrow_down_16x16

rationalize

clojure.core

  • (rationalize num)
returns the rational value of num

2 Examples top

  • user=> (rationalize 1.5)
    3/2
    
  • user=> (rationalize Math/PI)
    3141592653589793/1000000000000000
    
    user=> (rationalize (Math/sqrt 2))
    14142135623730951/10000000000000000
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/core.clj:1212 top

(defn rationalize
  "returns the rational value of num"
  {:added "1.0"
   :static true}
  [num]
  (. clojure.lang.Numbers (rationalize num)))
Vars in clojure.core/rationalize:
Used in 0 other vars

Comments top

1 comment(s) for rationalize.

Remember that for irrational numbers, like sqrt 2, this is only an estimate (pretty good one).

Log in to add a comment.