-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmath.lisp
32 lines (30 loc) · 1.04 KB
/
math.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
(defpackage :kiln/scripts/math
(:use :cl :alexandria :serapeum :with-c-syntax
:named-readtables)
(:import-from :floating-point-contractions
:lg :lb :ln :sq :hypot)
(:local-nicknames
(:c :with-c-syntax)
(:fp :floating-point-contractions))
(:documentation "Do math with C-style syntax but a Lisp numeric tower")
(:export :main))
(in-package :kiln/scripts/math)
(defun main (args)
(let* ((string (string-join args ""))
;; Print double floats without suffix.
(*read-default-float-format* 'double-float)
(*readtable*
(find-readtable 'c:with-c-syntax-readtable))
(*package*
(find-package :kiln/scripts/math)))
(format t "~a~%"
(handler-bind ((warning #'muffle-warning))
(eval
(read-from-string
(string+ "#2{" string "}#")))))))
(defsubst log1p (x) (fp:log1+ x))
(defsubst log1m (x) (fp:log1- x))
(defsubst expm1 (x) (fp:exp-1 x))
(defsubst exptm1 (a z) (fp:expt-1 a z))
(defsubst log10 (x) (lg x))
(defsubst log2 (x) (lb x))