chickadee » mathh

mathh

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

bessel-j0 Nprocedure
bessel-j1 Nprocedure
bessel-jn O Nprocedure
bessel-y0 Nprocedure
bessel-y1 Nprocedure
bessel-yn O Nprocedure

cosh

sinh

tanh

acosh

asinh

atanh

cosh Nprocedure
sinh Nprocedure
tanh Nprocedure
acosh Nprocedure
asinh Nprocedure
atanh Nprocedure

hypot

hypot N1 N2procedure

gamma

lgamma

gamma Nprocedure
lgamma Nprocedure

erf

erfc

erf Nprocedure
erfc Nprocedure

log10

log2

log1p

log10 Nprocedure
log2 Nprocedure
log1p Nprocedure

log-with-base

log-with-base Nprocedure

Returns a monadic function, the logarithm of base N.

ldexp

scalbn

ldexp N P2procedure
scalbn N P2procedure

cbrt

cbrt Nprocedure

nextafter

nextafter N Mprocedure

Returns the next N in the direction of M.

fpmod

fpmod N Mprocedure

Returns the modulus of N for M.

modf

modf Nprocedure

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

frexp

frexp Nprocedure

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

signbit

signbit Nprocedure

Returns #t when negative, #f otherwise.

copysign

copysign N Mprocedure

Returns N with same sign as M.

fpclassify

fpclassify Nprocedure

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

infinite
nan
normal
subnormal
zero
unclassified

fpclass

fpclass Nprocedure

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

Flonum Utilities

Usage

(require-extension fp-utils)

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

P is the precision in decimal digits, an integer.

fprandom

fprandom #!optional Nprocedure

Returns flonum in [0 -1).

N
fixnum or flonum limit.

fpzero?

fpzero? Nprocedure

fppositive?

fppositive? Nprocedure

Note that -0.0 is not positive, due to (fl<? -0.0 0.0).

fpcardinal?

fpcardinal? Nprocedure

Note that -0.0 is not cardinal, due to (fl<? -0.0 0.0).

fpnegative?

fpnegative? Nprocedure

Note that -0.0 is not negative, due to (fl<? -0.0 0.0).

fpeven?

fpeven? Nprocedure

fpodd?

fpodd? Nprocedure

fpclosed-right?

fpclosedr?

fpclosed-right? L N Hprocedure
fpclosedr? L N Hprocedure

Returns N in (L .. H].

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

fpclosed?

Returns N in [L .. H].

fpclosed? L N Hprocedure

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

fpclosed-left?

fpclosedl?

Returns N in [L .. H).

fpclosed-left? L N Hprocedure
fpclosedl? L N Hprocedure

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

fpadd1

fpadd1 Nprocedure

fpsub1

fpsub1 Nprocedure

fpmodulo

fpmodulo N1 N2procedure

fpquotient

fpquotient N1 N2procedure

fpremainder

fpremainder N1 N2procedure

fpfraction

fpfraction Nprocedure

fptruncate/precision

(fptruncate/precision N [P 4]) -> flonumprocedure

fpround/precision

(fpround/precision N [P 4]) -> flonumprocedure

fpceiling/precision

(fpceiling/precision N [P 4]) -> flonumprocedure

fpfloor/precision

(fpfloor/precision N [P 4]) -> flonumprocedure

fp~=

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

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

fp~<=

fp~<= Nprocedure

fp~>=

fp~>= Nprocedure

fpsqr

fpsqr Nprocedure

fpcub

fpcub Nprocedure

fpdegree->radian

fpdegree->radian Nprocedure

fpradian->degree

fpradian->degree Nprocedure

fpdistance

fpdistance X1 Y1 X2 Y2procedure

Pythagorean distance between the points X1 Y1 and X2 Y2.

fpdistance*

fpdistance* X1 Y1 X2 Y2procedure

Pythagorean distance, inaccurate but useful for relative comparisons.

fpmax-and-min

fpmax-and-min N ...procedure

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

fpprecision-factor

(fpprecision-factor P [BASE 10.0]) -> flonumprocedure

Returns factor for P decimal digits precision.

Fixnum Utilities

Usage

(require-extension fx-utils)

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

fxrandom

fxrandom #!optional Nprocedure

N fixnum limit.

fxzero?

fxzero? Nprocedure

fxpositive?

fxpositive? Nprocedure

fxcardinal?

fxcardinal? Nprocedure

fxnegative?

fxnegative? Nprocedure

fxclosed-right?

fxclosedr?

fxclosed-right? L N Hprocedure
fxclosedr? L N Hprocedure

Returns N in (L .. H].

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

fxclosed?

Returns N in [L .. H].

fxclosed? L N Hprocedure

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

fxclosed-left?

fxclosedl?

Returns N in [L .. H).

fxclosed-left? L N Hprocedure
fxclosedl? L N Hprocedure

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

fxadd1

fxadd1 Nprocedure

fxsub1

fxsub1 Nprocedure

fxabs

fxabs Nprocedure

fxsqr

fxsqr Nprocedure

fxcub

fxcub Nprocedure

fxlog2

fxlog2 Nprocedure

Returns index of highest bit set, so N is treated as unsigned.

fxpow2log2

fxpow2log2 Nprocedure

Returns fixnum 2^N.

fxdistance

fxdistance X1 Y1 X2 Y2procedure

Pythagorean distance between the points X1 Y1 and X2 Y2.

fxdistance*

fxdistance* X1 Y1 X2 Y2procedure

Pythagorean distance, inaccurate but useful for relative comparisons.

fxmax-and-min

fxmax-and-min N ...procedure

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

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)

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

Author

Kon Lovett John Cowan

Version history

3.4.2
Fix foreign-declare use. Fix fpzero?, fppositive?, fpnegative?, fpcardinal? again.
3.4.1
Remove unneeded dependency.
3.4.0 ; Fix fppositive?, fpnegative?, fpcardinal?, fpeven?, fpodd?.
3.3.3 ; Remove Windows log2, log1p, erf, erfc, scalbn.
3.3.2 ;
3.3.1 ;
3.3.0 ; Add log-with-base. Deprecate make-log/base. Fix fprandom sign preservation.
3.2.4 ; Add fxlog2, fix fxpow2log2.
3.2.3 ; Fix 4THRT2, 1/LNPHI, extend 1/SQRT2.
3.2.2 ; Remove inline generation for mathh.
3.2.1 ; Add types. Fix signbit & fpclass.
3.2.0 ; Fix fpodd?. Add fx-utils.scm. Extend fp-utils.scm.
3.1.0 ; Added module for mathh-constants.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.

Contents »