Carp/core/Long.carp

83 lines
2.3 KiB
Plaintext
Raw Permalink Normal View History

2018-01-24 18:08:18 +03:00
(system-include "carp_long.h")
2018-01-24 17:53:18 +03:00
2021-07-05 15:48:35 +03:00
(doc Long "is a bigger integral data type (its size is 64 bits). Its suffix is
`l`.")
2017-10-25 20:17:53 +03:00
(defmodule Long
(register MAX Long "LONG_MAX")
(register MIN Long "LONG_MIN")
2017-10-25 20:17:53 +03:00
(register + (λ [Long Long] Long))
(register - (λ [Long Long] Long))
(register * (λ [Long Long] Long))
(register / (λ [Long Long] Long))
(register < (λ [Long Long] Bool))
(register > (λ [Long Long] Bool))
(register = (λ [Long Long] Bool))
(register neg (λ [Long] Long))
2017-10-25 20:17:53 +03:00
(register mod (λ [Long Long] Long))
(register seed (λ [Long] ()))
2017-11-29 16:16:23 +03:00
(register bit-shift-left (λ [Long Long] Long))
(register bit-shift-right (λ [Long Long] Long))
(register bit-and (λ [Long Long] Long))
(register bit-or (λ [Long Long] Long))
(register bit-xor (λ [Long Long] Long))
(register bit-not (λ [Long] Long))
2017-10-25 20:17:53 +03:00
(register inc (λ [Long] Long))
(register dec (λ [Long] Long))
2017-11-29 13:45:20 +03:00
(register to-int (λ [Long] Int))
(register from-int (λ [Int] Long))
2019-06-22 21:18:32 +03:00
(todo copy "Should not be needed when refs to value types are auto-converted
to non-refs.")
(register copy (λ [&Long] Long))
2017-10-25 20:17:53 +03:00
(implements + Long.+)
(implements - Long.-)
(implements * Long.*)
(implements / Long./)
(implements < Long.<)
(implements > Long.>)
(implements = Long.=)
(implements copy Long.copy)
(implements inc Long.inc)
(implements dec Long.dec)
(implements neg Long.neg)
(implements mod Long.mod)
(implements to-int Long.to-int)
(implements from-int Long.from-int)
2020-07-08 22:11:13 +03:00
(implements bit-shift-left Long.bit-shift-left)
(implements bit-shift-right Long.bit-shift-right)
(implements bit-and Long.bit-and)
(implements bit-or Long.bit-or)
(implements bit-xor Long.bit-xor)
(implements bit-not Long.bit-not)
2020-05-12 21:24:40 +03:00
(posix-only ; this seems to generate invalid code on some windows machines
2020-04-24 11:28:00 +03:00
(register safe-add (λ [Long Long (Ref Long)] Bool))
(register safe-sub (λ [Long Long (Ref Long)] Bool))
(register safe-mul (λ [Long Long (Ref Long)] Bool))
)
2017-11-17 14:26:01 +03:00
(register abs (λ [Long] Long))
2017-11-29 17:28:21 +03:00
(defn even? [a] (= (mod a 2l) 0l))
(defn odd? [a] (not (even? a)))
(defn zero [] 0l)
(implements abs Long.abs)
(implements zero Long.zero)
2018-01-15 18:27:05 +03:00
)
(defmodule LongRef
(defn = [a b]
(Long.= @a @b))
(implements = LongRef.=)
2018-01-15 18:27:05 +03:00
(defn < [a b]
(Long.< @a @b))
(implements < LongRef.<)
2018-01-15 18:27:05 +03:00
(defn > [a b]
(Long.> @a @b))
(implements > LongRef.>)
2017-11-14 20:07:35 +03:00
)