1 | [[tags: egg]] |
---|
2 | |
---|
3 | == mathh |
---|
4 | |
---|
5 | [[toc:]] |
---|
6 | |
---|
7 | |
---|
8 | == Documentation |
---|
9 | |
---|
10 | Provides access to ISO C math functions in <math.h> that are not defined by |
---|
11 | the Chicken core. Please refer to your documentation for <math.h> for a |
---|
12 | description of the various calls. |
---|
13 | |
---|
14 | |
---|
15 | === Math Functions |
---|
16 | |
---|
17 | {{O}} is a {{fixnum}}. |
---|
18 | |
---|
19 | {{P2}} is an {{integer}}. |
---|
20 | |
---|
21 | {{N}}, {{M}}, {{N1}}, {{N2}} are {{float}}. |
---|
22 | |
---|
23 | ==== Usage |
---|
24 | |
---|
25 | <enscript language=scheme> |
---|
26 | (import "mathh") |
---|
27 | </enscript> |
---|
28 | |
---|
29 | ==== bessel-j0 |
---|
30 | ==== bessel-j1 |
---|
31 | ==== bessel-jn |
---|
32 | ==== bessel-jn |
---|
33 | ==== bessel-y0 |
---|
34 | ==== bessel-y1 |
---|
35 | ==== bessel-yn |
---|
36 | |
---|
37 | <procedure>(bessel-j0 N) --> float</procedure> |
---|
38 | <procedure>(bessel-j1 N) --> float</procedure> |
---|
39 | <procedure>(bessel-jn O N) --> float</procedure> |
---|
40 | <procedure>(bessel-y0 N) --> float</procedure> |
---|
41 | <procedure>(bessel-y1 N) --> float</procedure> |
---|
42 | <procedure>(bessel-yn O N) --> float</procedure> |
---|
43 | |
---|
44 | ==== cosh |
---|
45 | ==== sinh |
---|
46 | ==== tanh |
---|
47 | ==== acosh |
---|
48 | ==== asinh |
---|
49 | ==== atanh |
---|
50 | |
---|
51 | <procedure>(cosh N) --> float</procedure> |
---|
52 | <procedure>(sinh N) --> float</procedure> |
---|
53 | <procedure>(tanh N) --> float</procedure> |
---|
54 | <procedure>(acosh N) --> float</procedure> |
---|
55 | <procedure>(asinh N) --> float</procedure> |
---|
56 | <procedure>(atanh N) --> float</procedure> |
---|
57 | |
---|
58 | ==== hypot |
---|
59 | |
---|
60 | <procedure>(hypot N1 N2) --> float</procedure> |
---|
61 | |
---|
62 | ==== gamma |
---|
63 | ==== lgamma |
---|
64 | |
---|
65 | <procedure>(gamma N) --> float</procedure> |
---|
66 | <procedure>(lgamma N) --> float</procedure> |
---|
67 | |
---|
68 | ==== erf |
---|
69 | ==== erfc |
---|
70 | |
---|
71 | <procedure>(erf N) --> float</procedure> |
---|
72 | <procedure>(erfc N) --> float</procedure> |
---|
73 | |
---|
74 | ==== log10 |
---|
75 | ==== log2 |
---|
76 | ==== log1p |
---|
77 | |
---|
78 | <procedure>(log10 N) --> float</procedure> |
---|
79 | <procedure>(log2 N) --> float</procedure> |
---|
80 | <procedure>(log1p N) --> float</procedure> |
---|
81 | |
---|
82 | ==== log-with-base |
---|
83 | ==== log/base |
---|
84 | |
---|
85 | <procedure>(log-with-base N) --> (procedure (float) float)</procedure> |
---|
86 | <procedure>(log/base N) --> (procedure (float) float)</procedure> |
---|
87 | |
---|
88 | Returns a function for the logarithm of base {{N}}. |
---|
89 | |
---|
90 | ==== ldexp |
---|
91 | ==== scalbn |
---|
92 | |
---|
93 | <procedure>(ldexp N P2) --> float</procedure> |
---|
94 | <procedure>(scalbn N P2) --> float</procedure> |
---|
95 | |
---|
96 | ==== cbrt |
---|
97 | |
---|
98 | <procedure>(cbrt N) --> float</procedure> |
---|
99 | |
---|
100 | ==== nextafter |
---|
101 | |
---|
102 | <procedure>(nextafter N M) --> float</procedure> |
---|
103 | |
---|
104 | Returns the next {{N}} in the direction of {{M}}. |
---|
105 | |
---|
106 | ==== fpmod |
---|
107 | |
---|
108 | <procedure>(fpmod N M) --> float</procedure> |
---|
109 | |
---|
110 | Returns the modulus of {{N}} for {{M}}. |
---|
111 | |
---|
112 | ==== modf |
---|
113 | |
---|
114 | <procedure>(modf N) --> float float</procedure> |
---|
115 | |
---|
116 | Returns two values, the integral and fractional components of {{N}}. |
---|
117 | |
---|
118 | ==== modf* |
---|
119 | |
---|
120 | <procedure>(modf* N) --> integer float</procedure> |
---|
121 | |
---|
122 | Returns two values, the integral and fractional components of {{N}}. |
---|
123 | |
---|
124 | ==== frexp |
---|
125 | |
---|
126 | <procedure>(frexp N) --> float float</procedure> |
---|
127 | |
---|
128 | Returns two values, the fraction and the exponent components of {{N}}. |
---|
129 | |
---|
130 | ==== signbit |
---|
131 | |
---|
132 | <procedure>(signbit N) --> boolean</procedure> |
---|
133 | |
---|
134 | Returns {{#t}} when negative, {{#f}} otherwise. |
---|
135 | |
---|
136 | ==== copysign |
---|
137 | |
---|
138 | <procedure>(copysign N M) --> float</procedure> |
---|
139 | |
---|
140 | Returns {{N}} with same sign as {{M}}. |
---|
141 | |
---|
142 | ==== fpclassify |
---|
143 | |
---|
144 | <procedure>(fpclassify N) --> symbol</procedure> |
---|
145 | |
---|
146 | Returns a symbol denoting the floating-point kind of {{N}}. |
---|
147 | |
---|
148 | ; infinite : |
---|
149 | ; nan : |
---|
150 | ; normal : |
---|
151 | ; subnormal : |
---|
152 | ; zero : |
---|
153 | ; unclassified : |
---|
154 | |
---|
155 | ==== fpclass |
---|
156 | |
---|
157 | <procedure>(fpclass N) --> symbol</procedure> |
---|
158 | |
---|
159 | Returns a symbol denoting the floating-point kind of {{N}}. |
---|
160 | |
---|
161 | ; positive-infinite : |
---|
162 | ; negative-infinite : |
---|
163 | ; quiet-nan : |
---|
164 | ; signaling-nan : |
---|
165 | ; positive-normal : |
---|
166 | ; negative-normal : |
---|
167 | ; positive-subnormal : |
---|
168 | ; negative-subnormal : |
---|
169 | ; positive-zero : |
---|
170 | ; negative-zero : |
---|
171 | ; unclassified : |
---|
172 | |
---|
173 | |
---|
174 | === Math Constants (Module) |
---|
175 | |
---|
176 | ==== Usage |
---|
177 | |
---|
178 | <enscript language=scheme> |
---|
179 | (import mathh-consts) |
---|
180 | </enscript> |
---|
181 | |
---|
182 | ==== Constants |
---|
183 | |
---|
184 | These are all {{float}}. |
---|
185 | |
---|
186 | ; e : e |
---|
187 | ; 1/e : 1/e |
---|
188 | ; e^2 : e^2 |
---|
189 | ; e^pi/4 : e^(pi/4) |
---|
190 | ; log2e : log2(e) |
---|
191 | ; log10e : log10(e) |
---|
192 | ; ln2 : log(2) |
---|
193 | ; ln3 : ln(3) |
---|
194 | ; lnpi : ln(pi) |
---|
195 | ; ln10 : log(10) |
---|
196 | ; 1/ln2 : 1/ln(2) |
---|
197 | ; 1/ln10 : 1/ln(10) |
---|
198 | ; pi : pi |
---|
199 | ; pi/2 : pi/2 |
---|
200 | ; pi/4 : pi/4 |
---|
201 | ; 1/pi : 1/pi |
---|
202 | ; 2/pi : 2/pi |
---|
203 | ; 2/sqrtpi : 2/sqrt(pi) |
---|
204 | ; sqrtpi : sqrt(pi) |
---|
205 | ; pi^2 : pi^2 |
---|
206 | ; degree : pi/180 |
---|
207 | ; sqrt2 : sqrt(2) |
---|
208 | ; 1/sqrt2 : 1/sqrt(2) |
---|
209 | ; sqrt3 : sqrt(3) |
---|
210 | ; sqrt5 : sqrt(5) |
---|
211 | ; sqrt10 : sqrt(10) |
---|
212 | ; cubert2 : cubert(2) |
---|
213 | ; cubert3 : cubert(3) |
---|
214 | ; 4thrt2 : fourthrt(2) |
---|
215 | ; gamma1/2 : gamma(1/2) |
---|
216 | ; gamma1/3 : gamma(1/3) |
---|
217 | ; gamma2/3 : gamma(2/3) |
---|
218 | ; phi : phi |
---|
219 | ; lnphi : ln(phi) |
---|
220 | ; 1/lnphi : 1/ln(phi) |
---|
221 | ; euler : euler |
---|
222 | ; e^euler : e^euler |
---|
223 | ; sin1 : sin(1) |
---|
224 | ; cos1 : cos(1) |
---|
225 | ; zeta3 : theta(3) |
---|
226 | |
---|
227 | |
---|
228 | === Math Constants (Include) |
---|
229 | |
---|
230 | Common constants, using 'define-constant'. As such they must be textually |
---|
231 | included. |
---|
232 | |
---|
233 | ==== Usage |
---|
234 | |
---|
235 | <enscript language=scheme> |
---|
236 | (include "mathh-constants") |
---|
237 | </enscript> |
---|
238 | |
---|
239 | ==== Constants |
---|
240 | |
---|
241 | ; E : e |
---|
242 | ; 1/E : 1/e |
---|
243 | ; E^2 : e^2 |
---|
244 | ; E^PI/4 : e^(pi/4) |
---|
245 | ; LOG2E : log2(e) |
---|
246 | ; LOG10E : log10(e) |
---|
247 | ; LN2 : log(2) |
---|
248 | ; LN3 : ln(3) |
---|
249 | ; LNPI : ln(pi) |
---|
250 | ; LN10 : log(10) |
---|
251 | ; 1/LN2 : 1/ln(2) |
---|
252 | ; 1/LN10 : 1/ln(10) |
---|
253 | ; PI : pi |
---|
254 | ; PI/2 : pi/2 |
---|
255 | ; PI/4 : pi/4 |
---|
256 | ; 1/PI : 1/pi |
---|
257 | ; 2/PI : 2/pi |
---|
258 | ; 2/SQRTPI : 2/sqrt(pi) |
---|
259 | ; SQRTPI : sqrt(pi) |
---|
260 | ; PI^2 : pi^2 |
---|
261 | ; DEGREE : pi/180 |
---|
262 | ; SQRT2 : sqrt(2) |
---|
263 | ; 1/SQRT2 : 1/sqrt(2) |
---|
264 | ; SQRT3 : sqrt(3) |
---|
265 | ; SQRT5 : sqrt(5) |
---|
266 | ; SQRT10 : sqrt(10) |
---|
267 | ; CUBERT2 : cubert(2) |
---|
268 | ; CUBERT3 : cubert(3) |
---|
269 | ; 4THRT2 : fourthrt(2) |
---|
270 | ; GAMMA1/2 : gamma(1/2) |
---|
271 | ; GAMMA1/3 : gamma(1/3) |
---|
272 | ; GAMMA2/3 : gamma(2/3) |
---|
273 | ; PHI : phi |
---|
274 | ; LNPHI : ln(phi) |
---|
275 | ; 1/LNPHI : 1/ln(phi) |
---|
276 | ; EULER : euler |
---|
277 | ; E^EULER : e^euler |
---|
278 | ; SIN1 : sin(1) |
---|
279 | ; COS1 : cos(1) |
---|
280 | ; ZETA3 : theta(3) |
---|
281 | |
---|
282 | |
---|
283 | == Notes |
---|
284 | |
---|
285 | * The C library call {{gamma}} is deprecated in favor of {{tgamma}} but not |
---|
286 | available yet on some platforms, so we use {{gamma}} where necessary. |
---|
287 | |
---|
288 | * Some library calls that are not supplied by the platform have rough |
---|
289 | implementations supplied. See {{Bugs and Limitations}}. |
---|
290 | |
---|
291 | * The general naming convention is to use the C library call name as the Scheme |
---|
292 | name. But there are exceptions: |
---|
293 | |
---|
294 | ; fmod : fpmod |
---|
295 | ; j0 : bessel-j0 (Prefixed to distinguish the names from common variables) |
---|
296 | ; j1 : bessel-j1 |
---|
297 | ; jn : bessel-jn |
---|
298 | ; y0 : bessel-y0 |
---|
299 | ; y1 : bessel-y1 |
---|
300 | ; yn : bessel-yn |
---|
301 | |
---|
302 | |
---|
303 | == Bugs and Limitations |
---|
304 | |
---|
305 | * Given the notes above not current. |
---|
306 | |
---|
307 | * Support for the full numeric tower is '''not''' provided. |
---|
308 | |
---|
309 | * Windows library calls {{lgamma}}, {{gamma}}, {{acosh}}, {{asinh}}, |
---|
310 | {{atanh}}, {{cbrt}} & {{signbit}} are not provided. |
---|
311 | |
---|
312 | * FreeBSD does not provide the library call {{log2}}. A usable {{log2}} is |
---|
313 | supplied. |
---|
314 | |
---|
315 | * The {{fpclass}} {{quiet-nan}} is only distinguished on Windows. |
---|
316 | |
---|
317 | |
---|
318 | == Author |
---|
319 | |
---|
320 | [[/users/kon-lovett|Kon Lovett]] |
---|
321 | [[/users/john cowan|John Cowan]] |
---|
322 | |
---|
323 | |
---|
324 | == Version history |
---|
325 | |
---|
326 | ; 4.2.0 : Add {{modf*}}. |
---|
327 | ; 4.0.0 : CHICKEN 5 release. |
---|
328 | ; 3.4.2 : Fix foreign-declare use. Fix {{fpzero?}}, {{fppositive?}}, {{fpnegative?}}, {{fpcardinal?}} again. |
---|
329 | ; 3.4.1 : Remove unneeded dependency. |
---|
330 | ; 3.4.0 ; Fix {{fppositive?}}, {{fpnegative?}}, {{fpcardinal?}}, {{fpeven?}}, {{fpodd?}}. |
---|
331 | ; 3.3.3 ; Remove Windows {{log2}}, {{log1p}}, {{erf}}, {{erfc}}, {{scalbn}}. |
---|
332 | ; 3.3.2 ; |
---|
333 | ; 3.3.1 ; |
---|
334 | ; 3.3.0 ; Add {{log-with-base}}. Deprecate {{make-log/base}}. Fix {{fprandom}} sign preservation. |
---|
335 | ; 3.2.4 ; Add {{fxlog2}}, fix {{fxpow2log2}}. |
---|
336 | ; 3.2.3 ; Fix {{4THRT2}}, {{1/LNPHI}}, extend {{1/SQRT2}}. |
---|
337 | ; 3.2.2 ; Remove ''inline'' generation for mathh. |
---|
338 | ; 3.2.1 ; Add types. Fix {{signbit}} & {{fpclass}}. |
---|
339 | ; 3.2.0 ; Fix {{fpodd?}}. Add ''fx-utils.scm''. Extend ''fp-utils.scm''. |
---|
340 | ; 3.1.0 ; Added module for ''mathh-constants.scm''. |
---|
341 | ; 3.0.0 ; Moved copy of ''mathh-constants.scm'' to {{(chicken-home)}}. Ticket #1327 |
---|
342 | ; 2.2.6 ; better argvector chicken test |
---|
343 | ; 2.2.5 ; argvector chicken support |
---|
344 | ; 2.2.4 ; |
---|
345 | ; 2.2.3 ; Fix for ticket #630 |
---|
346 | ; 2.2.2 ; ''mathh-constants.scm'' copied to Chicken Repository. Produces shared+static object files. |
---|
347 | ; 2.2.1 : Better ''no-install'' support. |
---|
348 | ; 2.2.0 : Added {{acosh}}, {{asinh}}, {{atanh}}, {{erf}} & {{erfc}}. Includes <sunmath.h> on Sun platform for {{log2}}. |
---|
349 | ; 2.1.0 : Added {{signbit}}, {{copysign}}, {{nextafter}} & {{cbrt}}. |
---|
350 | ; 2.0.0 : Chicken 4 release. {{fpclass}} and {{fpclassify}} are now part of the '''mathh''' extension. |
---|
351 | |
---|
352 | |
---|
353 | == License |
---|
354 | |
---|
355 | This code is in the public domain. |
---|