application/octet-stream
•
1.00 KB
•
41 lines
;;; Nujel - Copyright (C) 2020-2021 - Benjamin Vincent Schulenburg
;;; This project uses the MIT license, a copy should be included under /LICENSE
;;;
;;; Some convenient math functions and constants
(def PI 3.141592653589793)
(def π PI)
(defn inc (x)
:inline
"Return a number 1 greater than x"
(+ 1 x))
(defn dec (x)
:inline
"Return a number 1 less than x"
(- x 1))
(defmacro inc! (i v)
"Decrement I by V (defaults to 1) and store the result in I"
`(set! ~i (+ ~i ~(or v 1))))
(defmacro dec! (i v)
"Decrement I by V and store the result in I"
`(set! ~i (- ~i ~(or v 1))))
(defn radians (degrees)
"Convert a quantity in degrees to radians"
(/ (* π degrees) 180.0))
(defn min args
"Returns the minimum value of its arguments"
:cat :math
(reduce args (fn (a b) (if (< a b) a b))))
(defn max args
"Returns the maximum value of its arguments"
:cat :math
(reduce args (fn (a b) (if (> a b) a b))))