mathh

  1. mathh
  2. Documentation
    1. Math Functions
      1. Usage
      2. bessel-j0
      3. bessel-j1
      4. bessel-jn
      5. bessel-jn
      6. bessel-y0
      7. bessel-y1
      8. bessel-yn
      9. cosh
      10. sinh
      11. tanh
      12. acosh
      13. asinh
      14. atanh
      15. hypot
      16. gamma
      17. lgamma
      18. erf
      19. erfc
      20. log10
      21. log2
      22. log1p
      23. make-log/base
      24. ldexp
      25. scalbn
      26. cbrt
      27. nextafter
      28. fpmod
      29. modf
      30. frexp
      31. signbit
      32. copysign
      33. fpclassify
      34. fpclass
    2. Math Constants (Module)
      1. Usage
      2. Constants
    3. Flonum Utilities
      1. Usage
    4. fprandom
      1. fpzero?
      2. fppositive?
      3. fpcardinal?
      4. fpnegative?
      5. fpeven?
      6. fpodd?
    5. fpclosed-right?
    6. fpclosedr?
    7. fpclosed?
    8. fpclosed-left?
    9. fpclosedl?
    10. fpadd1
    11. fpsub1
      1. fpmodulo
      2. fpquotient
      3. fpremainder
      4. fpfraction
      5. fptruncate/precision
      6. fpround/precision
      7. fpceiling/precision
      8. fpfloor/precision
      9. fp~=
    12. fp~<=
    13. fp~>=
      1. fpsqr
      2. fpcub
      3. fpdegree->radian
      4. fpradian->degree
      5. fpdistance
      6. fpdistance*
      7. fpmax-and-min
      8. fpprecision-factor
    14. Fixnum Utilities
      1. Usage
    15. fxrandom
      1. fxzero?
      2. fxpositive?
      3. fxcardinal?
      4. fxnegative?
    16. fxclosed-right?
    17. fxclosedr?
    18. fxclosed?
    19. fxclosed-left?
    20. fxclosedl?
    21. fxadd1
    22. fxsub1
      1. fxabs
      2. fxsqr
      3. fxcub
      4. fxpow2log2
      5. fxdistance
      6. fxdistance*
      7. fxmax-and-min
    23. Math Constants (Include)
      1. Usage
      2. Constants
  3. Notes
  4. Bugs and Limitations
  5. Author
  6. Version history
  7. License

Documentation

Provides access to ISO C math functions in <math.h> that are not defined by the Chicken core. Please refer to your documentation for <math.h> for a description of the various calls.

Math Functions

O, P2 are integer.

N, N1, N2, M are real.

Usage

(use "mathh")

bessel-j0

bessel-j1

bessel-jn

bessel-jn

bessel-y0

bessel-y1

bessel-yn

[procedure] (bessel-j0 N) => real
[procedure] (bessel-j1 N) => real
[procedure] (bessel-jn O N) => real
[procedure] (bessel-y0 N) => real
[procedure] (bessel-y1 N) => real
[procedure] (bessel-yn O N) => real

cosh

sinh

tanh

acosh

asinh

atanh

[procedure] (cosh N) => real
[procedure] (sinh N) => real
[procedure] (tanh N) => real
[procedure] (acosh N) => real
[procedure] (asinh N) => real
[procedure] (atanh N) => real

hypot

[procedure] (hypot N1 N2) => real

gamma

lgamma

[procedure] (gamma N) => real
[procedure] (lgamma N) => real

erf

erfc

[procedure] (erf N) => real
[procedure] (erfc N) => real

log10

log2

log1p

[procedure] (log10 N) => real
[procedure] (log2 N) => real
[procedure] (log1p N) => real

make-log/base

[procedure] (make-log/base N) => (provedure (real) real)

Returns a procedure of one argument, the logarithm function for the base N.

ldexp

scalbn

[procedure] (ldexp N P2) => real
[procedure] (scalbn N P2) => real

cbrt

[procedure] (cbrt N) => real

nextafter

[procedure] (nextafter N M) => real

Returns the next N in the direction of M.

fpmod

[procedure] (fpmod N M) => real

Returns the modulus of N for M.

modf

[procedure] (modf N) => (values real integer)

Returns two values, the integral and fractional components of N.

frexp

[procedure] (frexp N) => (values real real)

Returns two values, the fraction and the exponent components of N.

signbit

[procedure] (signbit N) => boolean

Returns #t when negative, #f otherwise.

copysign

[procedure] (copysign N M) => real

Returns N with same sign as M.

fpclassify

[procedure] (fpclassify N) => symbol

Returns a symbol denoting the floating-point kind of N.

infinite
nan
normal
subnormal
zero
unclassified

fpclass

[procedure] (fpclass N) => symbol

Returns a symbol denoting the floating-point kind of N.

positive-infinite
negative-infinite
quiet-nan
signaling-nan
positive-normal
negative-normal
positive-subnormal
negative-subnormal
positive-zero
negative-zero
unclassified

Math Constants (Module)

Usage

(require-extension mathh-consts)

Constants

These are all flonum.

e
e
1/e
1/e
e^2
e^2
e^pi/4
e^(pi/4)
log2e
log2(e)
log10e
log10(e)
ln2
log(2)
ln3
ln(3)
lnpi
ln(pi)
ln10
log(10)
1/ln2
1/ln(2)
1/ln10
1/ln(10)
pi
pi
pi/2
pi/2
pi/4
pi/4
1/pi
1/pi
2/pi
2/pi
2/sqrtpi
2/sqrt(pi)
sqrtpi
sqrt(pi)
pi^2
pi^2
degree
pi/180
sqrt2
sqrt(2)
1/sqrt2
1/sqrt(2)
sqrt3
sqrt(3)
sqrt5
sqrt(5)
sqrt10
sqrt(10)
cubert2
cubert(2)
cubert3
cubert(3)
4thrt2
fourthrt(2)
gamma1/2
gamma(1/2)
gamma1/3
gamma(1/3)
gamma2/3
gamma(2/3)
phi
phi
lnphi
ln(phi)
1/lnphi
1/ln(phi)
euler
euler
e^euler
e^euler
sin1
sin(1)
cos1
cos(1)
zeta3
theta(3)

Flonum Utilities

Usage

(require-extension fp-utils)

N N1 ... X1 ... Y1 ... below are flonum.

P is the precision in decimal digits, an integer.

fprandom

[procedure] (fprandom [N]) => flonum

N fixnum limit.

fpzero?

[procedure] (fpzero? N) => boolean

fppositive?

[procedure] (fppositive? N) => boolean

fpcardinal?

[procedure] (fpcardinal? N) => boolean

fpnegative?

[procedure] (fpnegative? N) => boolean

fpeven?

[procedure] (fpeven? N) => boolean

fpodd?

[procedure] (fpodd? N) => boolean

fpclosed-right?

fpclosedr?

[procedure] (fpclosed-right? L N H) => boolean
[procedure] (fpclosedr? L N H) => boolean

Returns N in (L .. H].

N, L & H are flonum low & high limits.

fpclosed?

Returns N in [L .. H].

[procedure] (fpclosed? L N H) => boolean

N, L & H are flonum low & high limits.

fpclosed-left?

fpclosedl?

Returns N in [L .. H).

[procedure] (fpclosed-left? L N H) => boolean
[procedure] (fpclosedl? L N H) => boolean

N, L & H are flonum low & high limits.

fpadd1

[procedure] (fpadd1 N) => flonum

fpsub1

[procedure] (fpsub1 N) => flonum

fpmodulo

[procedure] (fpmodulo N1 N2) => flonum

fpquotient

[procedure] (fpquotient N1 N2) => flonum

fpremainder

[procedure] (fpremainder N1 N2) => flonum

fpfraction

[procedure] (fpfraction N) => flonum

fptruncate/precision

[procedure] (fptruncate/precision N [P 4]) => flonum

fpround/precision

[procedure] (fpround/precision N [P 4]) => flonum

fpceiling/precision

[procedure] (fpceiling/precision N [P 4]) => flonum

fpfloor/precision

[procedure] (fpfloor/precision N [P 4]) => flonum

fp~=

[procedure] (fp~= N1 N2 [EPS flonum-epsilon]) => flonum

Compare floating-point values N1 and N2 within some flonum epsilon EPS.

fp~<=

[procedure] (fp~<= N) => boolean

fp~>=

[procedure] (fp~>= N) => boolean

fpsqr

[procedure] (fpsqr N) => flonum

fpcub

[procedure] (fpcub N) => flonum

fpdegree->radian

[procedure] (fpdegree->radian N) => flonum

fpradian->degree

[procedure] (fpradian->degree N) => flonum

fpdistance

[procedure] (fpdistance X1 Y1 X2 Y2) => flonum

Pythagorean distance between the points X1 Y1 and X2 Y2.

fpdistance*

[procedure] (fpdistance* X1 Y1 X2 Y2) => flonum

Pythagorean distance, inaccurate but useful for relative comparisons.

fpmax-and-min

[procedure] (fpmax-and-min N ...) => (values flonum flonum)

Returns the maximum & minimum values for the flonums N ....

fpprecision-factor

[procedure] (fpprecision-factor P [BASE 10.0]) => flonum

Returns factor for P decimal digits precision.

Fixnum Utilities

Usage

(require-extension fx-utils)

N N1 ... X1 ... Y1 ... below are fixnum.

fxrandom

[procedure] (fxrandom [N]) => fixnum

N fixnum limit.

fxzero?

[procedure] (fxzero? N) => boolean

fxpositive?

[procedure] (fxpositive? N) => boolean

fxcardinal?

[procedure] (fxcardinal? N) => boolean

fxnegative?

[procedure] (fxnegative? N) => boolean

fxclosed-right?

fxclosedr?

[procedure] (fxclosed-right? L N H) => boolean
[procedure] (fxclosedr? L N H) => boolean

Returns N in (L .. H].

N, L & H are fixnum low & high limits.

fxclosed?

Returns N in [L .. H].

[procedure] (fxclosed? L N H) => boolean

N, L & H are fixnum low & high limits.

fxclosed-left?

fxclosedl?

Returns N in [L .. H).

[procedure] (fxclosed-left? L N H) => boolean
[procedure] (fxclosedl? L N H) => boolean

N, L & H are fixnum low & high limits.

fxadd1

[procedure] (fxadd1 N) => fixnum

fxsub1

[procedure] (fxsub1 N) => fixnum

fxabs

[procedure] (fxabs N) => fixnum

fxsqr

[procedure] (fxsqr N) => fixnum

fxcub

[procedure] (fxcub N) => fixnum

fxpow2log2

[procedure] (fxpow2log2 N) => fixnum

Returns fixnum 2^N.

fxdistance

[procedure] (fxdistance X1 Y1 X2 Y2) => fixnum

Pythagorean distance between the points X1 Y1 and X2 Y2.

fxdistance*

[procedure] (fxdistance* X1 Y1 X2 Y2) => fixnum

Pythagorean distance, inaccurate but useful for relative comparisons.

fxmax-and-min

[procedure] (fxmax-and-min N ...) => (values fixnum fixnum)

Returns the maximum & minimum values for the fixnums N ....

Math Constants (Include)

Common constants, using 'define-constant'. As such they must be textually included.

Usage

(include "mathh-constants")

Constants

E
e
1/E
1/e
E^2
e^2
E^PI/4
e^(pi/4)
LOG2E
log2(e)
LOG10E
log10(e)
LN2
log(2)
LN3
ln(3)
LNPI
ln(pi)
LN10
log(10)
1/LN2
1/ln(2)
1/LN10
1/ln(10)
PI
pi
PI/2
pi/2
PI/4
pi/4
1/PI
1/pi
2/PI
2/pi
2/SQRTPI
2/sqrt(pi)
SQRTPI
sqrt(pi)
PI^2
pi^2
DEGREE
pi/180
SQRT2
sqrt(2)
1/SQRT2
1/sqrt(2)
SQRT3
sqrt(3)
SQRT5
sqrt(5)
SQRT10
sqrt(10)
CUBERT2
cubert(2)
CUBERT3
cubert(3)
4THRT2
fourthrt(2)
GAMMA1/2
gamma(1/2)
GAMMA1/3
gamma(1/3)
GAMMA2/3
gamma(2/3)
PHI
phi
LNPHI
ln(phi)
1/LNPHI
1/ln(phi)
EULER
euler
E^EULER
e^euler
SIN1
sin(1)
COS1
cos(1)
ZETA3
theta(3)

Notes

fmod
fpmod - fp-utils fpmodulo - should be in Chicken library?
j0
bessel-j0 (Prefixed to distinguish the names from common variables)
j1
bessel-j1
jn
bessel-jn
y0
bessel-y0
y1
bessel-y1
yn
bessel-yn

Bugs and Limitations

Usable log2, log1p, erf, erfc, scalbn & signbit are supplied.

Author

Kon Lovett John Cowan

Version history

3.1.1 ; Fix fpodd?. Add fx-utils.scm. Extend fp-utils.scm.
3.2.0 ; Added module for mathh-constants.scm. Added fp-utils.scm.
3.0.0 ; Moved copy of mathh-constants.scm to (chicken-home). Ticket #1327
2.2.6 ; better argvector chicken test
2.2.5 ; argvector chicken support
2.2.4 ;
2.2.3 ; Fix for ticket #630
2.2.2 ; mathh-constants.scm copied to Chicken Repository. Produces shared+static object files.
2.2.1
Better no-install support.
2.2.0
Added acosh, asinh, atanh, erf & erfc. Includes <sunmath.h> on Sun platform for log2.
2.1.0
Added signbit, copysign, nextafter & cbrt.
2.0.0
Chicken 4 release. fpclass and fpclassify are now part of the mathh extension.

License

This code is in the public domain.