((section 2 "Outdated egg!" (p "This is an egg for CHICKEN 4, the unsupported old release.  You're almost certainly looking for " (int-link "/eggref/5/mathh" "the CHICKEN 5 version of this egg") ", if it exists.") (p "If it does not exist, there may be equivalent functionality provided by another egg; have a look at the " (link "https://wiki.call-cc.org/chicken-projects/egg-index-5.html" "egg index") ". Otherwise, please consider porting this egg to the current version of CHICKEN.") (tags "egg")) (section 2 "mathh" (toc)) (section 2 "Documentation" (p "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.") (section 3 "Math Functions" (p (tt "O") ", " (tt "P2") " are " (tt "integer") ".") (p (tt "N") ", " (tt "N1") ", " (tt "N2") ", " (tt "M") " are " (tt "real") ".") (section 4 "Usage" (highlight scheme "(use \"mathh\")")) (section 4 "bessel-j0") (section 4 "bessel-j1") (section 4 "bessel-jn") (section 4 "bessel-jn") (section 4 "bessel-y0") (section 4 "bessel-y1") (section 4 "bessel-yn" (def (sig (procedure "(bessel-j0 N) -> real" (id bessel-j0)) (procedure "(bessel-j1 N) -> real" (id bessel-j1)) (procedure "(bessel-jn O N) -> real" (id bessel-jn)) (procedure "(bessel-y0 N) -> real" (id bessel-y0)) (procedure "(bessel-y1 N) -> real" (id bessel-y1)) (procedure "(bessel-yn O N) -> real" (id bessel-yn))))) (section 4 "cosh") (section 4 "sinh") (section 4 "tanh") (section 4 "acosh") (section 4 "asinh") (section 4 "atanh" (def (sig (procedure "(cosh N) -> real" (id cosh)) (procedure "(sinh N) -> real" (id sinh)) (procedure "(tanh N) -> real" (id tanh)) (procedure "(acosh N) -> real" (id acosh)) (procedure "(asinh N) -> real" (id asinh)) (procedure "(atanh N) -> real" (id atanh))))) (section 4 "hypot" (def (sig (procedure "(hypot N1 N2) -> real" (id hypot))))) (section 4 "gamma") (section 4 "lgamma" (def (sig (procedure "(gamma N) -> real" (id gamma)) (procedure "(lgamma N) -> real" (id lgamma))))) (section 4 "erf") (section 4 "erfc" (def (sig (procedure "(erf N) -> real" (id erf)) (procedure "(erfc N) -> real" (id erfc))))) (section 4 "log10") (section 4 "log2") (section 4 "log1p" (def (sig (procedure "(log10 N) -> real" (id log10)) (procedure "(log2 N) -> real" (id log2)) (procedure "(log1p N) -> real" (id log1p))))) (section 4 "log-with-base" (def (sig (procedure "(log-with-base N) -> (procedure (real) real)" (id log-with-base))) (p "Returns a monadic function, the logarithm of base " (tt "N") "."))) (section 4 "ldexp") (section 4 "scalbn" (def (sig (procedure "(ldexp N P2) -> real" (id ldexp)) (procedure "(scalbn N P2) -> real" (id scalbn))))) (section 4 "cbrt" (def (sig (procedure "(cbrt N) -> real" (id cbrt))))) (section 4 "nextafter" (def (sig (procedure "(nextafter N M) -> real" (id nextafter))) (p "Returns the next " (tt "N") " in the direction of " (tt "M") "."))) (section 4 "fpmod" (def (sig (procedure "(fpmod N M) -> real" (id fpmod))) (p "Returns the modulus of " (tt "N") " for " (tt "M") "."))) (section 4 "modf" (def (sig (procedure "(modf N) -> (values real integer)" (id modf))) (p "Returns two values, the integral and fractional components of " (tt "N") "."))) (section 4 "frexp" (def (sig (procedure "(frexp N) -> (values real real)" (id frexp))) (p "Returns two values, the fraction and the exponent components of " (tt "N") "."))) (section 4 "signbit" (def (sig (procedure "(signbit N) -> boolean" (id signbit))) (p "Returns " (tt "#t") " when negative, " (tt "#f") " otherwise."))) (section 4 "copysign" (def (sig (procedure "(copysign N M) -> real" (id copysign))) (p "Returns " (tt "N") " with same sign as " (tt "M") "."))) (section 4 "fpclassify" (def (sig (procedure "(fpclassify N) -> symbol" (id fpclassify))) (p "Returns a symbol denoting the floating-point kind of " (tt "N") ".") (dl (dt "infinite") (dt "nan") (dt "normal") (dt "subnormal") (dt "zero") (dt "unclassified")))) (section 4 "fpclass" (def (sig (procedure "(fpclass N) -> symbol" (id fpclass))) (p "Returns a symbol denoting the floating-point kind of " (tt "N") ".") (dl (dt "positive-infinite") (dt "negative-infinite") (dt "quiet-nan") (dt "signaling-nan") (dt "positive-normal") (dt "negative-normal") (dt "positive-subnormal") (dt "negative-subnormal") (dt "positive-zero") (dt "negative-zero") (dt "unclassified"))))) (section 3 "Flonum Utilities" (section 4 "Usage" (highlight scheme "(require-extension fp-utils)") (p (tt "N N1 ... X1 ... Y1 ...") " below are " (tt "flonum") ".") (p (tt "P") " is the precision in decimal digits, an " (tt "integer") ".")) (section 4 "fprandom" (def (sig (procedure "(fprandom [N]) -> flonum" (id fprandom))) (p "Returns " (tt "flonum") " in " (tt "[0 -1)") ".") (dl (dt (tt "N")) (dd (tt "fixnum") " or " (tt "flonum") " limit.")))) (section 4 "fpzero?" (def (sig (procedure "(fpzero? N) -> boolean" (id fpzero?))))) (section 4 "fppositive?" (def (sig (procedure "(fppositive? N) -> boolean" (id fppositive?))) (p "Note that " (tt "-0.0") " is " (b "not") " positive, due to " (tt "(fl<? -0.0 0.0)") "."))) (section 4 "fpcardinal?" (def (sig (procedure "(fpcardinal? N) -> boolean" (id fpcardinal?))) (p "Note that " (tt "-0.0") " is " (b "not") " cardinal, due to " (tt "(fl<? -0.0 0.0)") "."))) (section 4 "fpnegative?" (def (sig (procedure "(fpnegative? N) -> boolean" (id fpnegative?))) (p "Note that " (tt "-0.0") " is " (b "not") " negative, due to " (tt "(fl<? -0.0 0.0)") "."))) (section 4 "fpeven?" (def (sig (procedure "(fpeven? N) -> boolean" (id fpeven?))))) (section 4 "fpodd?" (def (sig (procedure "(fpodd? N) -> boolean" (id fpodd?))))) (section 4 "fpclosed-right?") (section 4 "fpclosedr?" (def (sig (procedure "(fpclosed-right? L N H) -> boolean" (id fpclosed-right?)) (procedure "(fpclosedr? L N H) -> boolean" (id fpclosedr?))) (p "Returns " (tt "N") " in " (tt "(L .. H]") ".") (p (tt "N") ", " (tt "L") " & " (tt "H") " are " (tt "flonum") " low & high limits."))) (section 4 "fpclosed?" (p "Returns " (tt "N") " in " (tt "[L .. H]") ".") (def (sig (procedure "(fpclosed? L N H) -> boolean" (id fpclosed?))) (p (tt "N") ", " (tt "L") " & " (tt "H") " are " (tt "flonum") " low & high limits."))) (section 4 "fpclosed-left?") (section 4 "fpclosedl?" (p "Returns " (tt "N") " in " (tt "[L .. H)") ".") (def (sig (procedure "(fpclosed-left? L N H) -> boolean" (id fpclosed-left?)) (procedure "(fpclosedl? L N H) -> boolean" (id fpclosedl?))) (p (tt "N") ", " (tt "L") " & " (tt "H") " are " (tt "flonum") " low & high limits."))) (section 4 "fpadd1" (def (sig (procedure "(fpadd1 N) -> flonum" (id fpadd1))))) (section 4 "fpsub1" (def (sig (procedure "(fpsub1 N) -> flonum" (id fpsub1))))) (section 4 "fpmodulo" (def (sig (procedure "(fpmodulo N1 N2) -> flonum" (id fpmodulo))))) (section 4 "fpquotient" (def (sig (procedure "(fpquotient N1 N2) -> flonum" (id fpquotient))))) (section 4 "fpremainder" (def (sig (procedure "(fpremainder N1 N2) -> flonum" (id fpremainder))))) (section 4 "fpfraction" (def (sig (procedure "(fpfraction N) -> flonum" (id fpfraction))))) (section 4 "fptruncate/precision" (def (sig (procedure "(fptruncate/precision N [P 4]) -> flonum" (id fptruncate/precision))))) (section 4 "fpround/precision" (def (sig (procedure "(fpround/precision N [P 4]) -> flonum" (id fpround/precision))))) (section 4 "fpceiling/precision" (def (sig (procedure "(fpceiling/precision N [P 4]) -> flonum" (id fpceiling/precision))))) (section 4 "fpfloor/precision" (def (sig (procedure "(fpfloor/precision N [P 4]) -> flonum" (id fpfloor/precision))))) (section 4 "fp~=" (def (sig (procedure "(fp~= N1 N2 [EPS flonum-epsilon]) -> flonum" (id fp~=))) (p "Compare floating-point values " (tt "N1") " and " (tt "N2") " within some " (tt "flonum") " epsilon " (tt "EPS") "."))) (section 4 "fp~<=" (def (sig (procedure "(fp~<= N) -> boolean" (id fp~<=))))) (section 4 "fp~>=" (def (sig (procedure "(fp~>= N) -> boolean" (id fp~>=))))) (section 4 "fpsqr" (def (sig (procedure "(fpsqr N) -> flonum" (id fpsqr))))) (section 4 "fpcub" (def (sig (procedure "(fpcub N) -> flonum" (id fpcub))))) (section 4 "fpdegree->radian" (def (sig (procedure "(fpdegree->radian N) -> flonum" (id fpdegree->radian))))) (section 4 "fpradian->degree" (def (sig (procedure "(fpradian->degree N) -> flonum" (id fpradian->degree))))) (section 4 "fpdistance" (def (sig (procedure "(fpdistance X1 Y1 X2 Y2) -> flonum" (id fpdistance))) (p "Pythagorean distance between the points " (tt "X1 Y1") " and " (tt "X2 Y2") "."))) (section 4 "fpdistance*" (def (sig (procedure "(fpdistance* X1 Y1 X2 Y2) -> flonum" (id fpdistance*))) (p "Pythagorean distance, inaccurate but useful for relative comparisons."))) (section 4 "fpmax-and-min" (def (sig (procedure "(fpmax-and-min N ...) -> (values flonum flonum)" (id fpmax-and-min))) (p "Returns the maximum & minimum values for the " (tt "flonum") "s " (tt "N ...") "."))) (section 4 "fpprecision-factor" (def (sig (procedure "(fpprecision-factor P [BASE 10.0]) -> flonum" (id fpprecision-factor))) (p "Returns factor for " (tt "P") " decimal digits precision.")))) (section 3 "Fixnum Utilities" (section 4 "Usage" (highlight scheme "(require-extension fx-utils)") (p (tt "N N1 ... X1 ... Y1 ...") " below are " (tt "fixnum") ".")) (section 4 "fxrandom" (def (sig (procedure "(fxrandom [N]) -> fixnum" (id fxrandom))) (p (tt "N") " " (tt "fixnum") " limit."))) (section 4 "fxzero?" (def (sig (procedure "(fxzero? N) -> boolean" (id fxzero?))))) (section 4 "fxpositive?" (def (sig (procedure "(fxpositive? N) -> boolean" (id fxpositive?))))) (section 4 "fxcardinal?" (def (sig (procedure "(fxcardinal? N) -> boolean" (id fxcardinal?))))) (section 4 "fxnegative?" (def (sig (procedure "(fxnegative? N) -> boolean" (id fxnegative?))))) (section 4 "fxclosed-right?") (section 4 "fxclosedr?" (def (sig (procedure "(fxclosed-right? L N H) -> boolean" (id fxclosed-right?)) (procedure "(fxclosedr? L N H) -> boolean" (id fxclosedr?))) (p "Returns " (tt "N") " in " (tt "(L .. H]") ".") (p (tt "N") ", " (tt "L") " & " (tt "H") " are " (tt "fixnum") " low & high limits."))) (section 4 "fxclosed?" (p "Returns " (tt "N") " in " (tt "[L .. H]") ".") (def (sig (procedure "(fxclosed? L N H) -> boolean" (id fxclosed?))) (p (tt "N") ", " (tt "L") " & " (tt "H") " are " (tt "fixnum") " low & high limits."))) (section 4 "fxclosed-left?") (section 4 "fxclosedl?" (p "Returns " (tt "N") " in " (tt "[L .. H)") ".") (def (sig (procedure "(fxclosed-left? L N H) -> boolean" (id fxclosed-left?)) (procedure "(fxclosedl? L N H) -> boolean" (id fxclosedl?))) (p (tt "N") ", " (tt "L") " & " (tt "H") " are " (tt "fixnum") " low & high limits."))) (section 4 "fxadd1" (def (sig (procedure "(fxadd1 N) -> fixnum" (id fxadd1))))) (section 4 "fxsub1" (def (sig (procedure "(fxsub1 N) -> fixnum" (id fxsub1))))) (section 4 "fxabs" (def (sig (procedure "(fxabs N) -> fixnum" (id fxabs))))) (section 4 "fxsqr" (def (sig (procedure "(fxsqr N) -> fixnum" (id fxsqr))))) (section 4 "fxcub" (def (sig (procedure "(fxcub N) -> fixnum" (id fxcub))))) (section 4 "fxlog2" (def (sig (procedure "(fxlog2 N) -> fixnum" (id fxlog2))) (p "Returns index of highest bit set, so " (tt "N") " is treated as unsigned."))) (section 4 "fxpow2log2" (def (sig (procedure "(fxpow2log2 N) -> fixnum" (id fxpow2log2))) (p "Returns " (tt "fixnum") " " (tt "2^N") "."))) (section 4 "fxdistance" (def (sig (procedure "(fxdistance X1 Y1 X2 Y2) -> fixnum" (id fxdistance))) (p "Pythagorean distance between the points " (tt "X1 Y1") " and " (tt "X2 Y2") "."))) (section 4 "fxdistance*" (def (sig (procedure "(fxdistance* X1 Y1 X2 Y2) -> fixnum" (id fxdistance*))) (p "Pythagorean distance, inaccurate but useful for relative comparisons."))) (section 4 "fxmax-and-min" (def (sig (procedure "(fxmax-and-min N ...) -> (values fixnum fixnum)" (id fxmax-and-min))) (p "Returns the maximum & minimum values for the " (tt "fixnum") "s " (tt "N ...") ".")))) (section 3 "Math Constants (Module)" (section 4 "Usage" (highlight scheme "(require-extension mathh-consts)")) (section 4 "Constants" (p "These are all " (tt "flonum") ".") (dl (dt "e") (dd "e") (dt "1/e") (dd "1/e") (dt "e^2") (dd "e^2") (dt "e^pi/4") (dd "e^(pi/4)") (dt "log2e") (dd "log2(e)") (dt "log10e") (dd "log10(e)") (dt "ln2") (dd "log(2)") (dt "ln3") (dd "ln(3)") (dt "lnpi") (dd "ln(pi)") (dt "ln10") (dd "log(10)") (dt "1/ln2") (dd "1/ln(2)") (dt "1/ln10") (dd "1/ln(10)") (dt "pi") (dd "pi") (dt "pi/2") (dd "pi/2") (dt "pi/4") (dd "pi/4") (dt "1/pi") (dd "1/pi") (dt "2/pi") (dd "2/pi") (dt "2/sqrtpi") (dd "2/sqrt(pi)") (dt "sqrtpi") (dd "sqrt(pi)") (dt "pi^2") (dd "pi^2") (dt "degree") (dd "pi/180") (dt "sqrt2") (dd "sqrt(2)") (dt "1/sqrt2") (dd "1/sqrt(2)") (dt "sqrt3") (dd "sqrt(3)") (dt "sqrt5") (dd "sqrt(5)") (dt "sqrt10") (dd "sqrt(10)") (dt "cubert2") (dd "cubert(2)") (dt "cubert3") (dd "cubert(3)") (dt "4thrt2") (dd "fourthrt(2)") (dt "gamma1/2") (dd "gamma(1/2)") (dt "gamma1/3") (dd "gamma(1/3)") (dt "gamma2/3") (dd "gamma(2/3)") (dt "phi") (dd "phi") (dt "lnphi") (dd "ln(phi)") (dt "1/lnphi") (dd "1/ln(phi)") (dt "euler") (dd "euler") (dt "e^euler") (dd "e^euler") (dt "sin1") (dd "sin(1)") (dt "cos1") (dd "cos(1)") (dt "zeta3") (dd "theta(3)")))) (section 3 "Math Constants (Include)" (p "Common constants, using 'define-constant'. As such they must be textually included.") (section 4 "Usage" (highlight scheme "(include \"mathh-constants\")")) (section 4 "Constants" (dl (dt "E") (dd "e") (dt "1/E") (dd "1/e") (dt "E^2") (dd "e^2") (dt "E^PI/4") (dd "e^(pi/4)") (dt "LOG2E") (dd "log2(e)") (dt "LOG10E") (dd "log10(e)") (dt "LN2") (dd "log(2)") (dt "LN3") (dd "ln(3)") (dt "LNPI") (dd "ln(pi)") (dt "LN10") (dd "log(10)") (dt "1/LN2") (dd "1/ln(2)") (dt "1/LN10") (dd "1/ln(10)") (dt "PI") (dd "pi") (dt "PI/2") (dd "pi/2") (dt "PI/4") (dd "pi/4") (dt "1/PI") (dd "1/pi") (dt "2/PI") (dd "2/pi") (dt "2/SQRTPI") (dd "2/sqrt(pi)") (dt "SQRTPI") (dd "sqrt(pi)") (dt "PI^2") (dd "pi^2") (dt "DEGREE") (dd "pi/180") (dt "SQRT2") (dd "sqrt(2)") (dt "1/SQRT2") (dd "1/sqrt(2)") (dt "SQRT3") (dd "sqrt(3)") (dt "SQRT5") (dd "sqrt(5)") (dt "SQRT10") (dd "sqrt(10)") (dt "CUBERT2") (dd "cubert(2)") (dt "CUBERT3") (dd "cubert(3)") (dt "4THRT2") (dd "fourthrt(2)") (dt "GAMMA1/2") (dd "gamma(1/2)") (dt "GAMMA1/3") (dd "gamma(1/3)") (dt "GAMMA2/3") (dd "gamma(2/3)") (dt "PHI") (dd "phi") (dt "LNPHI") (dd "ln(phi)") (dt "1/LNPHI") (dd "1/ln(phi)") (dt "EULER") (dd "euler") (dt "E^EULER") (dd "e^euler") (dt "SIN1") (dd "sin(1)") (dt "COS1") (dd "cos(1)") (dt "ZETA3") (dd "theta(3)"))))) (section 2 "Notes" (ul (li "The C library call " (tt "gamma") " is deprecated in favor of " (tt "tgamma") " but not available yet on some platforms, so we use " (tt "gamma") " where necessary.") (li "Some library calls that are not supplied by the platform have rough implementations supplied. See " (tt "Bugs and Limitations") ".") (li "The general naming convention is to use the C library call name as the Scheme name. But there are exceptions:")) (dl (dt "fmod") (dd "fpmod - " (i "fp-utils") " " (tt "fpmodulo") " - should be in Chicken library?") (dt "j0") (dd "bessel-j0 (Prefixed to distinguish the names from common variables)") (dt "j1") (dd "bessel-j1") (dt "jn") (dd "bessel-jn") (dt "y0") (dd "bessel-y0") (dt "y1") (dd "bessel-y1") (dt "yn") (dd "bessel-yn"))) (section 2 "Bugs and Limitations" (ul (li "CHICKEN_INCLUDE_PATH must at least state the value of the " (tt "(repository-path)") " to include " (i "mathh-constants.scm") ". Suggest using the module " (i "mathh-consts") ".") (li "The types " (tt "integer") " & " (tt "real") " refer to the Chicken \"core\" concept of a number. Support for the full numeric tower is " (b "not") " provided.") (li "Windows library calls " (tt "lgamma") ", " (tt "gamma") ", " (tt "acosh") ", " (tt "asinh") ", " (tt "atanh") ", " (tt "cbrt") " & " (tt "signbit") " are not provided.") (li "FreeBSD does not provide the library call " (tt "log2") ". A usable " (tt "log2") " is supplied.") (li "The " (tt "fpclass") " " (tt "quiet-nan") " is only distinguished on Windows.") (li (i "fx-utils.scm") " & " (i "fp-utils.scm") " belong in own eggs."))) (section 2 "Author" (p (int-link "/users/kon-lovett" "Kon Lovett") " " (int-link "/users/john cowan" "John Cowan"))) (section 2 "Version history" (dl (dt "3.4.2") (dd "Fix foreign-declare use. Fix " (tt "fpzero?") ", " (tt "fppositive?") ", " (tt "fpnegative?") ", " (tt "fpcardinal?") " again.") (dt "3.4.1") (dd "Remove unneeded dependency.") (dt "3.4.0 ; Fix " (tt "fppositive?") ", " (tt "fpnegative?") ", " (tt "fpcardinal?") ", " (tt "fpeven?") ", " (tt "fpodd?") ".") (dt "3.3.3 ; Remove Windows " (tt "log2") ", " (tt "log1p") ", " (tt "erf") ", " (tt "erfc") ", " (tt "scalbn") ".") (dt "3.3.2 ;") (dt "3.3.1 ;") (dt "3.3.0 ; Add " (tt "log-with-base") ". Deprecate " (tt "make-log/base") ". Fix " (tt "fprandom") " sign preservation.") (dt "3.2.4 ; Add " (tt "fxlog2") ", fix " (tt "fxpow2log2") ".") (dt "3.2.3 ; Fix " (tt "4THRT2") ", " (tt "1/LNPHI") ", extend " (tt "1/SQRT2") ".") (dt "3.2.2 ; Remove " (i "inline") " generation for mathh.") (dt "3.2.1 ; Add types. Fix " (tt "signbit") " & " (tt "fpclass") ".") (dt "3.2.0 ; Fix " (tt "fpodd?") ". Add " (i "fx-utils.scm") ". Extend " (i "fp-utils.scm") ".") (dt "3.1.0 ; Added module for " (i "mathh-constants.scm") ".") (dt "3.0.0 ; Moved copy of " (i "mathh-constants.scm") " to " (tt "(chicken-home)") ". Ticket #1327") (dt "2.2.6 ; better argvector chicken test") (dt "2.2.5 ; argvector chicken support") (dt "2.2.4 ;") (dt "2.2.3 ; Fix for ticket #630") (dt "2.2.2 ; " (i "mathh-constants.scm") " copied to Chicken Repository. Produces shared+static object files.") (dt "2.2.1") (dd "Better " (i "no-install") " support.") (dt "2.2.0") (dd "Added " (tt "acosh") ", " (tt "asinh") ", " (tt "atanh") ", " (tt "erf") " & " (tt "erfc") ". Includes <sunmath.h> on Sun platform for " (tt "log2") ".") (dt "2.1.0") (dd "Added " (tt "signbit") ", " (tt "copysign") ", " (tt "nextafter") " & " (tt "cbrt") ".") (dt "2.0.0") (dd "Chicken 4 release. " (tt "fpclass") " and " (tt "fpclassify") " are now part of the " (b "mathh") " extension."))) (section 2 "License" (p "This code is in the public domain.")))