added to the library

parent 8f1c34c6
......@@ -111,7 +111,9 @@ SOURCES = \
language/python/module/genericpath.py \
language/python/module/posixpath.py \
language/python/module/fnmatch.py \
language/python/module/optparse.py
language/python/module/optparse.py \
language/python/module/selectors.py \
language/python/module/socket.py
......
(define-module (language python module math)
#:use-module (language python for)
#:use-module (language python try)
#:use-module (language python list)
#:use-module (language python exceptions)
#:use-module (language python number)
#:use-module (system foreign)
......@@ -8,9 +9,9 @@
#:export (ceil copysign fabs factorial floor fmod frexp fsum gcd isclose
isfinite isinf isnan modf trunc exp expm1 log log1p log2 log10
pow sqrt acos asin atan cos sin tan atan2 hypot pi
pow sqrt acos asin atan cos sin tan atan2 hypot pi prod
degrees radians acosh asinh atanh cosh sinh tanh
erf erfc gamma lgamma e tau inf nan))
erf erfc gamma lgamma e tau inf nan dist isqrt))
(define (real! s x)
(if (complex? x)
......@@ -42,6 +43,9 @@
1
(* x (lp (- x 1))))))
(define (isqrt x)
(inexact->exact (floor (sqrt x))))
(define (floor x)
((@ (guile) inexac->exact)
((@ (guile) floor)
......@@ -62,6 +66,11 @@
(for ((x : it)) ((s 0))
(+ s x)
#:final s))
(define* (prod it #:key (start 1))
(for ((x : it)) ((s start))
(* s x)
#:final s))
(define gcd (@ (guile) gcd))
......@@ -137,13 +146,11 @@
(list double double))))
(lambda (x y) (f x y))))
(define hypot
(let ((f (pointer->procedure double
(dynamic-func "hypot" (dynamic-link))
(list double double))))
(lambda (x y) (f x y))))
(define (hypot x)
(for ((i : x)) ((s 0))
(+ (* i i) s)
#:final
(sqrt s)))
;; angular conversion
(define pi (* 4 (atan 1)))
......@@ -200,3 +207,16 @@
(define tau (* 2 pi))
(define inf ((@ (guile) inf)))
(define nan ((@ (guile) nan)))
(define (dist x y)
(let ((n1 (len x))
(n2 (len y)))
(if (= n1 n2)
(for ((i : x) (j : y)) ((s 0))
(let ((d (- i j)))
(+ (* d d) s))
#:final
(sqrt s))
(raise (ValueError "in math.dist x and y must have the same length")))))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment