;;;; 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) (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)) ; (define (fpzero? n) (or (fp= 0.0 n) (fp= -0.0 n))) (: fppositive? (float --> boolean)) ; (define (fppositive? n) (fp< 0.0 n)) (: fpnatural? (float --> boolean)) ; (define (fpnatural? n) (fp<= 0.0 n)) (: fpnegative? (float --> boolean)) ; (define (fpnegative? n) (fp> 0.0 n)) (: fpnon-positive? (float --> boolean)) ; (define (fpnon-positive? n) (fp>= 0.0 n)) ;; (: fpeven? (float --> boolean)) ; (define (fpeven? n) (fpinteger? (fp/ n 2.0))) (: fpodd? (float --> boolean)) ; (define (fpodd? n) (not (fpeven? n))) ;; (: fpclosed-right? (float float float --> boolean)) ; (define (fpclosed-right? l x h) (and (fp< l x) (fp<= x h))) (: fpclosed? (float float float --> boolean)) ; (define (fpclosed? l x h) (and (fp<= l x) (fp<= x h))) (: fpclosed-left? (float float float --> boolean)) ; (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)) ;; (: fpadd1 (float --> float)) ; (define (fpadd1 n) (fp+ n 1.0)) (: fpsub1 (float --> float)) ; (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))) ;; (: fplog2 (float --> float)) ; (define (fplog2 x) (fp/ (fplog x) 0.6931471805599453094172321214581765680755)) (: fplog10 (float --> float)) ; (define (fplog10 x) (fp/ (fplog x) 2.3025850929940456840179914546843642076011)) ;; (: fpdegree->radian (float --> float)) ; (define (fpdegree->radian deg) (fp* deg 0.0174532925199432957692369076848861271344)) (: fpradian->degree (float --> float)) ; (define (fpradian->degree rad) (fp/ rad 0.0174532925199432957692369076848861271344)) ;; (: fpprecision-factor ((or float fixnum) #!optional float --> float)) ; (define (fpprecision-factor p #!optional (base 10.0)) (fpexpt base (exact->inexact p))) ) ;fp-inlines