mathh
TOC »
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 ; fixnum. : P2 ; integer. : N, M, N1, N2 ; float.
Usage
(import "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
- cosh Nprocedure
sinh
- sinh Nprocedure
tanh
- tanh Nprocedure
acosh
- acosh Nprocedure
asinh
- asinh Nprocedure
atanh
- atanh Nprocedure
hypot
- hypot N1 N2procedure
gamma
- gamma Nprocedure
lgamma
- lgamma Nprocedure
erf
- erf Nprocedure
erfc
- erfc Nprocedure
log10
- log10 Nprocedure
log2
- log2 Nprocedure
log1p
- log1p Nprocedure
log-with-base
log/base
- log-with-base Bprocedure
- log/base Bprocedure
Returns a function for the base B logarithm.
ldexp
- ldexp N P2procedure
scalbn
- 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*
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
Notes
- Some library calls that are not supplied by the platform have rough implementations supplied. See Bugs and Limitations.
- The general naming convention is to use the C library call name as the Scheme name. But there are exceptions:
- fmod
- fpmod
- 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
Math Constants (Module)
Usage
(import mathh-consts)
Constants
These are all float.
- 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)
Miscellaneous Math Functions
Note that unlike mathh the domain & range are number, not float.
Usage
(import misc-math-utils)
number->sign
- number->sign Nprocedure
Returns -1, 0, or +1 to represent the sign of the number N.
log-with-base
log/base
- log-with-base Bprocedure
- log/base Bprocedure
Returns a function for the base B logarithm.
simple-interest
- simple-interest RATE TIME #!optional PRINprocedure
The accumulation function, the principle is assumed 1. Returns the simple interest for the RATE over TIME.
- RATE ; number ; interest rate
- TIME ; number ; time period to cover
- PRIN ; number ; principle, default 1
compound-interest
- compound-interest RATE FREQ TIME #!optional PRINprocedure
The accumulation function, the principle is assumed 1. Returns the compound interest for the RATE, applied with FREQ, over TIME.
- RATE ; number ; interest rate
- FREQ ; number ; compounding frequency
- TIME ; number ; time period to cover
- PRIN ; number ; principle, default 1
(compound-interest 0.043 4 6 1500) ;=> 1938.84 ;rounded to 2 places
fibonacci
- fibonacci Nprocedure
Returns fibonacci of N.
fibonacci*
- fibonacci* Nprocedure
Returns an approximate fibonacci of N.
binomial
- binomial N1 N2procedure
Returns the Binomial in N1 to N2.
: N1 ; integer ; : N2 ; integer ;
cross-ratio
- cross-ratio N1 N2 N3 N4procedure
Returns the Cross-ratio of N1, N2 and N3, N4.
: N1 ; number ; : N2 ; number ; : N3 ; number ; : N4 ; number ;
square
- square Nprocedure
cube
- cube Nprocedure
average
- average N1 N2 ...procedure
- average NUMSprocedure
: N1 ; number ; : N1 ; number ;
: NUMS ; (list-of number) ;
least-squares
- least-squares PNTSprocedure
Returns b & e such that y ~= b * x + e.
: PNTS ; (list-of (pair number number)) ; list of x,y pairs
trapezoid
- trapezoid F N1 N2procedure
Returns a function to calculate the area under F between N1 & N2 using the Trapezoid Rule. The function takes the number of estimations as an argument, larger for a "better" result.
: F ; (number -> number) ; : N1 ; number ; : N2 ; number ;
factorial
factorial-
factorial+
- factorial Nprocedure
- factorial- N1 FALLprocedure
- factorial+ N1 RISEprocedure
: N ; integer ; : FALL : number ; falling factorial : RISE : number ; rising factorial
harmonic
- harmonic Nprocedure
Result of Harmonic series expansion to N terms.
: N ; integer ;
big-pi
- (big-pi F N1 N2) -> numbersyntax
Product of F in N1 to N2.
: F ; (number -> number) ; : N1 ; number ; : N2 ; number ;
big-sigma
- (big-sigma F N1 N2) -> numbersyntax
Sum of F in N1 to N2.
: F ; (number -> number) ; : N1 ; number ; : N2 ; number ;
Miscellaneous Vector Math Functions
Usage
(import misc-vector-math-utils)
absolute-magnitude
- absolute-magnitude NUMVECprocedure
- NUMVEC
- (vector-of number) ; .
cosine-similarity
- cosine-similarity NUMVEC1 NUMVEC2procedure
- NUMVEC1
- (vector-of number) ; .
- NUMVEC2
- (vector-of number) ; .
Must be same vector-length.
dot-product
- dot-product NUMVEC1 NUMVEC2procedure
- NUMVEC1
- (vector-of number) ; .
- NUMVEC2
- (vector-of number) ; .
Must be same vector-length.
cross-product
- cross-product NUMVEC1 NUMVEC2procedure
- NUMVEC1
- (vector-of number) ; .
- NUMVEC2
- (vector-of number) ; .
Must be same vector-length.
Only defined for a vector-length of (0 1 2), returning a number, and (3 4 8), returning a (vector-of number). All others generate an error.
vector-mul
vector-sum
vector-div
vector-dif
vector-min
vector-max
vector-lcm
vector-gcd
- vector-mul NUMVEC1 NUMVEC2 #!optional NUMVEC...procedure
- vector-sum NUMVEC1 NUMVEC2 #!optional NUMVEC...procedure
- vector-div NUMVEC1 NUMVEC2 #!optional NUMVEC...procedure
- vector-dif NUMVEC1 NUMVEC2 #!optional NUMVEC...procedure
- vector-min NUMVEC1 NUMVEC2 #!optional NUMVEC...procedure
- vector-max NUMVEC1 NUMVEC2 #!optional NUMVEC...procedure
- vector-lcm NUMVEC1 NUMVEC2 #!optional NUMVEC...procedure
- vector-gcd NUMVEC1 NUMVEC2 #!optional NUMVEC...procedure
- NUMVEC#
- (vector-of number) ; .
Must be same vector-length.
vector<?
vector=?
vector>?
vector<=?
vector>=?
- vector<? NUMVEC1 NUMVEC2 #!optional NUMVEC...procedure
- vector=? NUMVEC1 NUMVEC2 #!optional NUMVEC...procedure
- vector>? NUMVEC1 NUMVEC2 #!optional NUMVEC...procedure
- vector<=? NUMVEC1 NUMVEC2 #!optional NUMVEC...procedure
- vector>=? NUMVEC1 NUMVEC2 #!optional NUMVEC...procedure
- NUMVEC#
- (vector-of number) ; .
Must be same vector-length.
vector-compare
- (vector-compare NUMVEC1 NUMVEC2 -> (vector-of number)procedure
Result is (vector-dif NUMVEC2 NUMVEC1).
- NUMVEC1
- (vector-of number) ; .
- NUMVEC2
- (vector-of number) ; .
Must be same vector-length.
vector-apply
- vector-apply FUNC VEC1 VEC2 #!optional VEC...procedure
- FUNC
- (* * !#rest * -> *) ; .
- VEC#
- vector ; .
Must be same vector-length.
Requirements
Bugs and Limitations
- The fpclass quiet-nan is only distinguished on Windows.
Author
Repository
This egg is hosted on the CHICKEN Subversion repository:
https://anonymous@code.call-cc.org/svn/chicken-eggs/release/5/mathh
If you want to check out the source code repository of this egg and you are not familiar with Subversion, see this page.
Version history
- 4.6.4
- Add number->sign. Add test dependency.
- 4.6.3
- Remove vector-apply numeric restriction.
- 4.6.2
- Add vector-mul/div/sum/dif/min/max/lcm/gcd, vector</=/>/<=/>, vector-compare, vector-apply.
- 4.6.1
- Add vector-product & vector-sum. Fix cross-product(3).
- 4.6.0
- Add misc-vector-math-utils.
- 4.5.1
- Fix for include source mathh-constants.scm.
- 4.5.0
- Add log function to misc-math-utils.
- 4.4.0
- Add interest functions to misc-math-utils.
- 4.3.0
- Remove Windows restrictions (C2 era), assume BSD has tgamma.
- 4.2.3
- .
- 4.2.2
- .
- 4.2.1
- .
- 4.2.0
- Add modf*.
- 4.0.0
- CHICKEN 5 release.
License
This code is in the public domain.