Login
7 branches 0 tags
Ben (X13/Arch) Added a string-port and built [string/write/new] with that b1d5bb5 3 years ago 815 Commits
nujel / stdlib / math / math.nuj
;; Nujel - Copyright (C) 2020-2021 - Benjamin Vincent Schulenburg
;; This project uses the MIT license, a copy should be included under /LICENSE

[def PI 3.141592653589793]
[def π  3.141592653589793]

[defn inc [x]
      :inline
      "Return a number 1 greater than x"
      [+ 1 x]]

[defmacro inc! [i v]
          "Decrement I by V (defaults to 1) and store the result in I"
          `[set! ~i [+ ~i ~[or v 1]]]]

[defn dec [x]
      :inline
      "Return a number 1 less than x"
      [+ -1 x]]

[defmacro dec! [i v]
          "Decrement I by V and store the result in I"
          `[set! ~i [- ~i ~[or v 1]]]]

[defn +x [α]
      "Return a function that adds α to it's argument, useful for mapping"
      [fn [β]
          [+ α β]]]

[defn fib [i]
      "Terribly inefficient, but, useful for testing the GC"
      [if [< i 2] i
          [+ [fib [- i 2]] [fib [- i 1]]]]]

[defn wrap-value [val min max] "Constrains VAL to be within MIN and MAX, wrapping it around"
      [+ min [rem [- val min] [- max min]]]]

[defmacro +1 [v]
          `[+ 1 ~v]]

[defn radians [degrees]
      "Convert a quantity in degrees to radians"
      [/ [* π degrees] 180.0]]