;;;; mathh.scm ;;;; Provides access to ISO C math functions in ;;;; that are not defined by Chicken ;;;; Public domain ;;; Scheme-level declarations (declare (bound-to-procedure cosh sinh tanh log10 fmod modf ldexp frexp)) ;;; Include proper C header (foreign-declare "#include ") ;;; Hyperbolic functions (define cosh (foreign-lambda double cosh double)) (define sinh (foreign-lambda double sinh double)) (define tanh (foreign-lambda double tanh double)) ;;; Base-10 logarithm (define log10 (foreign-lambda double log10 double)) ;;; Flonum remainder (define fmod (foreign-lambda double fmod double double)) ;;; Return integer, fraction (as multiple values) of a flonum (define modf (foreign-primitive ((double x)) "double ipart; double result; C_word* values; C_word value1; C_word value2; result = modf(x, &ipart); values = C_alloc(2*C_SIZEOF_FLONUM); value1 = C_flonum(&values, ipart); value2 = C_flonum(&values, result); C_values(4, C_SCHEME_UNDEFINED, C_k, value1, value2); ")) ;;; Efficiently compute (* x (expt 2 y)) (define ldexp (foreign-lambda double ldexp double double)) ;;; Return mantissa, exponent (as multiple values) of a flonum (define frexp (foreign-primitive ((double x)) "int exp; double result; C_word* values; C_word value1; C_word value2; result = frexp(x, &exp); values = C_alloc(C_SIZEOF_FLONUM); value1 = C_flonum(&values, result); value2 = C_fix(exp); C_values(4, C_SCHEME_UNDEFINED, C_k, value1, value2); "))