;;;; fp-inlines.scm -*- Scheme -*- ;;;; Kon Lovett, Sep '18 ;;;; Issues ;; ;; - all instances of (fl< -0.0 0.0) found ? (module fp-inlines (;export fpzero? fppositive? fpnegative? fpnon-positive? fpnatural? fpeven? fpodd? fpclosed-right? fpclosed? fpclosed-left? fpclosedr? fpclosedl? fpadd1 fpsub1 fpsqr fpcub fplog2 fplog10 fpdegree->radian fpradian->degree fpprecision-factor fpprecision-epsilon) (import scheme) (import (chicken type)) (import (chicken flonum)) ;;;(mathh/mathh-constants) ;(define-constant FPLN2 0.6931471805599453094172321214581765680755) ;ln(2) ;(define-constant FPLN10 2.3025850929940456840179914546843642076011) ;ln(10) ;(define-constant FPDEG2RAD 0.0174532925199432957692369076848861271344) ;pi/180 ;(define-constant FP~EPS flonum-epsilon) ;;; ;; (: fpzero? (float --> boolean)) (: fppositive? (float --> boolean)) (: fpnatural? (float --> boolean)) (: fpnegative? (float --> boolean)) (: fpnon-positive? (float --> boolean)) (: fpeven? (float --> boolean)) (: fpodd? (float --> boolean)) (: fpclosed-right? (float float float --> boolean)) (: fpclosed? (float float float --> boolean)) (: fpclosed-left? (float float float --> boolean)) (: fpadd1 (float --> float)) (: fpsub1 (float --> float)) (: fplog2 (float --> float)) (: fplog10 (float --> float)) (: fpdegree->radian (float --> float)) (: fpradian->degree (float --> float)) (: fpprecision-factor ((or float fixnum) #!optional float --> float)) (: fpprecision-epsilon ((or float fixnum) #!optional float --> float)) (: fp% (float float --> float)) ;; (define (fpzero? n) (or (fp= 0.0 n) (fp= -0.0 n))) (define (fppositive? n) (fp< 0.0 n)) (define (fpnatural? n) (fp<= 0.0 n)) (define (fpnegative? n) (fp> 0.0 n)) (define (fpnon-positive? n) (fp>= 0.0 n)) ;; (define (fpeven? n) (fpinteger? (fp/ n 2.0))) (define (fpodd? n) (not (fpeven? n))) ;; (define (fpclosed-right? l x h) (and (fp< l x) (fp<= x h))) (define (fpclosed? l x h) (and (fp<= l x) (fp<= x h))) (define (fpclosed-left? l x h) (and (fp<= l x) (fp< x h))) ;inline, remember (define (fpclosedr? l x h) (fpclosed-right? l x h)) (define (fpclosedl? l x h) (fpclosed-left? l x h)) ;; (define (fpadd1 n) (fp+ n 1.0)) (define (fpsub1 n) (fp- n 1.0)) ;; (: fpsqr (float --> float)) ; (define (fpsqr n) (fp* n n)) (: fpcub (float --> float)) ; (define (fpcub n) (fp* n (fp* n n))) ;; (define (fplog2 x) (fp/ (fplog x) 0.6931471805599453094172321214581765680755)) (define (fplog10 x) (fp/ (fplog x) 2.3025850929940456840179914546843642076011)) ;; (define (fpdegree->radian deg) (fp* deg 0.0174532925199432957692369076848861271344)) (define (fpradian->degree rad) (fp/ rad 0.0174532925199432957692369076848861271344)) ;; (define (fpprecision-factor p #!optional (base 10.0)) (fpexpt base (exact->inexact p))) (define (fpprecision-epsilon p #!optional (base 10.0)) (fp/ 1.0 (fpprecision-factor p base))) ;; (define (fp% n p) (fp/ (fp* 100.0 n) (exact->inexact p))) ) ;fp-inlines