-
Notifications
You must be signed in to change notification settings - Fork 2
number
TurtleKitty edited this page May 10, 2019
·
3 revisions
A number may be an int or a real int values answer all the messages of real values plus a few of their own.
(num? x) -> returns true if x is a number
(int? x) -> returns true if x is an integer
(num? 1) ; true
(num? 1/2) ; true
(num? 2.3) ; true
(num? "23") ; false
(int? 1) ; true
(int? 2/1) ; true
(int? 2.0) ; true
(int? 1/2) ; false
(int? 2.3) ; false
(def x 1)
(def y 2.3)
(def z 0)
(def w -1)
x.type ; (int number)
y.type ; (real number)
z.type ; (int number)
x.zero? ; false
y.zero? ; false
z.zero? ; true
x.pos? ; true
x.neg? ; false
w.pos? ; false
w.neg? ; true
z.pos? ; false
z.neg? ; false
; <number>.abs returns the absolute value
x.abs ; 1
w.abs ; 1
; <number>.to-bool returns false if x is 0, true otherwise.
x.to-bool ; true
w.to-bool ; true
z.to-bool ; false
(def pi math.pi)
(def e math.e)
(def anti-e (* e -1))
x.to-text ; "1"
pi.to-text ; "3.14159265358979"
e.to-text ; "2.71828182845905"
pi.floor ; 3
pi.ceil ; 4
pi.round ; 3
e.floor ; 2
e.ceil ; 3
e.round ; 3
e.truncate ; 2
anti-e.floor ; -3
anti-e.ceil ; -2
anti-e.round ; -3
anti-e.truncate ; -2
; int-only messages
x.inc ; 2
x.dec ; 0
x.even? ; false
x.odd? ; true