-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathmath.lisp
57 lines (45 loc) · 1.87 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
;; -*- Mode: LISP; Syntax: COMMON-LISP; Package: CLPYTHON.MODULE.MATH -*-
;;
;; This software is Copyright (c) Franz Inc. and Willem Broekema.
;; Franz Inc. and Willem Broekema grant you the rights to
;; distribute and use this software as governed by the terms
;; of the Lisp Lesser GNU Public License
;; (http://opensource.franz.com/preamble.html),
;; known as the LLGPL.
(in-package :clpython.module.math)
(defgeneric conv (x)
(:method ((x number)) x)
(:method (x) (clpython:py-float x)))
(defconstant-once |e| (cl:exp 1))
(defconstant-once |pi| cl:pi)
(set-impl-status '(|pi| |e|) t)
(defmacro def-unary-conv-func (math cl)
`(defun ,math (x) (,cl (conv x))))
(def-unary-conv-func |sin| cl:sin)
(def-unary-conv-func |cos| cl:cos)
(def-unary-conv-func |tan| cl:tan)
(def-unary-conv-func |asin| cl:asin)
(def-unary-conv-func |acos| cl:acos)
(def-unary-conv-func |atan| cl:atan)
(def-unary-conv-func |sinh| cl:sinh)
(def-unary-conv-func |cosh| cl:cosh)
(def-unary-conv-func |tanh| cl:tanh)
(set-impl-status '(|sin| |cos| |tan| |asin| |acos| |atan| |sinh| |cosh| |tanh|) t)
(set-impl-status '|atan2| :todo "CL does not have it?")
(defun |ceil| (x) (cl:ceiling (conv x)))
(set-impl-status '(|ceil| |floor|) t)
(defun |exp| (x) (cl:exp x))
(defun |pow| (x y) (cl:expt (conv x) (conv y)))
(defun |log| (x) (cl:log x))
(defun |log10| (x) (cl:log (conv x) 10))
(defun |sqrt| (x) (cl:sqrt x))
(set-impl-status '(|exp| |pow| |log| |log10| |sqrt|) t)
(set-impl-status '(|degrees| |radians|) :todo)
(defun |fmod| (x y) (cl:mod (conv x) (conv y)))
(defun |fabs| (x) (cl:abs (conv x)))
(defun |modf| (x) (make-tuple-from-list (multiple-value-list (cl:truncate (conv x)))))
(set-impl-status '(|fmod| |fabs| |modf|) t)
(set-impl-status '|frexp| :todo)
(defun |hypot| (x y) (cl:abs (cl:complex (conv x) (conv y))))
(defun |ldexp| (x y) (* x (cl:expt 2 (conv y))))
(set-impl-status '(|hypot| |ldexp|) t)