Changeset 35160 in project


Ignore:
Timestamp:
02/18/18 23:10:49 (4 months ago)
Author:
kon
Message:

windows math.h has log2, log1p, erf, erfc, scalbn so remove statics

Location:
release/4/mathh/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • release/4/mathh/trunk/fp-utils.scm

    r35009 r35160  
    44;;;; Issues
    55;;;;
     6
     7(module fp-utils
     8
     9(;export
     10  ;
     11  ;check-inexact
     12  ;
     13  fprandom
     14  ;
     15  fpzero? fppositive? fpcardinal? fpnegative? fpnon-positive?
     16  ;
     17  fpeven? fpodd?
     18  ;
     19  fpclosed-right? fpclosed? fpclosed-left? fpclosedr? fpclosedl?
     20  ;
     21  fpadd1 fpsub1
     22  ;
     23  fpmodulo
     24  fpquotient fpremainder
     25  ;
     26  fpfraction
     27  ;
     28  fptruncate-with-precision
     29  fpround-with-precision
     30  fpceiling-with-precision
     31  fpfloor-with-precision
     32  ;
     33  fp~= fp~<= fp~>=
     34  ;
     35  fpsqr fpcub
     36  ;
     37  fpdegree->radian fpradian->degree
     38  ;
     39  fpdistance fpdistance*
     40  ;
     41  fpmax-and-min
     42  ;
     43  fpprecision-factor
     44  ;DEPRECATED
     45  fptruncate/precision fpround/precision fpceiling/precision fpfloor/precision)
     46
     47(import scheme chicken foreign)
     48
     49(use
     50  extras
     51  (only mathh log10))
    652
    753(declare
     
    1056    ##sys#check-inexact) )
    1157
    12 (module fp-utils
    13 
    14 (;export
    15   ;
    16   ;check-inexact
    17   ;
    18   fprandom
    19   ;
    20   fpzero? fppositive? fpcardinal? fpnegative? fpnon-positive?
    21   ;
    22   fpeven? fpodd?
    23   ;
    24   fpclosed-right? fpclosed? fpclosed-left? fpclosedr? fpclosedl?
    25   ;
    26   fpadd1 fpsub1
    27   ;
    28   fpmodulo
    29   fpquotient fpremainder
    30   ;
    31   fpfraction
    32   ;
    33   fptruncate-with-precision
    34   fpround-with-precision
    35   fpceiling-with-precision
    36   fpfloor-with-precision
    37   ;
    38   fp~= fp~<= fp~>=
    39   ;
    40   fpsqr fpcub
    41   ;
    42   fpdegree->radian fpradian->degree
    43   ;
    44   fpdistance fpdistance*
    45   ;
    46   fpmax-and-min
    47   ;
    48   fpprecision-factor
    49   ;DEPRECATED
    50   fptruncate/precision fpround/precision fpceiling/precision fpfloor/precision)
    51 
    52 (import scheme)
    53 
    54 (import chicken foreign extras)
    55 
    56 (use (only mathh log10))
    57 
    5858;;;
    5959
     
    7777
    7878(: fprandom (#!optional (or float fixnum) -> float))
    79 (define (fprandom #!optional (lim most-positive-fixnum))
    80   (let (
     79(define (fprandom #!optional lim (low 0))
     80  (let* (
     81    (low (inexact->exact low))
    8182    (lim
    82       (if (flonum? lim)
    83         (let (
    84           (sign? (fpnegative? lim) )
    85           (lim (inexact->exact (expt 10 (abs (round (log10 lim))))) ) )
    86           ;
    87           (if sign? (fxneg lim) lim) )
    88         ;else fixnum!
    89         lim ) ) )
    90     ;
    91     (fp/ 1.0 (exact->inexact (random lim))) ) )
     83      (cond
     84        ((not lim)
     85          most-positive-fixnum )
     86        ((flonum? lim)
     87          (let (
     88            (sign? (fpnegative? lim) )
     89            (lim (inexact->exact (expt 10 (abs (round (log10 lim))))) ) )
     90            (if sign? (fxneg lim) lim) ) )
     91        (else
     92          lim ) ) ) )
     93    (if (fx>= low lim)
     94      +nan.0
     95      (let* (
     96        (dif (fx- lim low))
     97        (rnd (random dif))
     98        (rnd (fx+ low rnd)) )
     99        (fp/ 1.0 (exact->inexact rnd)) ) ) ) )
    92100
    93101;;
  • release/4/mathh/trunk/fx-utils.scm

    r35009 r35160  
    109109
    110110(: fxrandom (#!optional fixnum -> fixnum))
    111 (define (fxrandom #!optional (x most-positive-fixnum))
    112   (*fxrandom x) )
     111(define (fxrandom #!optional lim (low 0))
     112  (let* (
     113    (lim (if (not lim) most-positive-fixnum lim))
     114    (dif (fx- lim low))
     115    (rnd (*fxrandom dif))
     116    (rnd (fx+ low rnd)) )
     117    rnd ) )
    113118
    114119;;
  • release/4/mathh/trunk/mathh.meta

    r34503 r35160  
    77 (doc-from-wiki)
    88 (synopsis "ISO C math functions and constants")
    9  (depends (setup-helper "1.5.2"))
     9 (depends (setup-helper "2.2.0"))
    1010 (test-depends test)
    1111 (files
  • release/4/mathh/trunk/mathh.scm

    r35143 r35160  
    1717;; acosh, asinh, atanh, erf, erfc, signbit, cbrt.
    1818;; Some are implemented (poorly) here: log2, log1p, erf, erfc, scalbn, signbit.
     19;; These are now defunct log2, log1p, erf, erfc, scalbn
    1920;;
    2021;; - 'gamma' is deprecated in favor of 'tgamma' but not available
     
    5859
    5960#if defined(__sun__) || defined(__sun)
    60 
    6161# include <sunmath.h> /* log2 */
    62 
    63 /* _WIN32 should be enough but ... */
    64 #elif defined(__CYGWIN__) || defined(__MINGW32__) || defined(_WIN32) || defined(WIN32) || defined(__WIN32__) || defined(__MINGW64__) || defined(_WIN64) || defined(WIN64) || defined(__WIN64__)
    65 
    66 static double
    67 log2( double x )
     62#endif
     63
     64/* log2, log1p, erf, erfc, scalbn were not originally provided */
     65#if 0
     66/* defined(__CYGWIN__) || defined(__MINGW32__) || defined(_WIN32) || defined(WIN32) || defined(__WIN32__) || defined(__MINGW64__) || defined(_WIN64) || defined(WIN64) || defined(__WIN64__)*/
     67static double log2( double x )
    6868{
    6969# ifndef M_LN2
     
    7373}
    7474
    75 static double
    76 log1p( double x )
     75static double log1p( double x )
    7776{
    7877  /* very imprecise */
     
    8180
    8281/* from a Python implementation by John D. Cook */
    83 static double
    84 erf( double x )
     82static double erf( double x )
    8583{
    8684# define A1 0.254829592
     
    108106}
    109107
    110 static double
    111 erfc( double x )
     108static double erfc( double x )
    112109{
    113110  /* very imprecise */
     
    115112}
    116113
    117 static double
    118 scalbn( double x, int n )
     114static double scalbn( double x, int n )
    119115{
    120116  /* not efficient */
    121117  return ldexp( x, n );
    122118}
    123 
    124119#endif
     120
    125121<#
    126122
     
    179175;; Error functions
    180176
    181 (define erf
    182   (cond-expand
    183     (windows  (foreign-lambda double "erf" double) )
    184     (else     (foreign-lambda double "erf" double) ) ) )
    185 
    186 (define erfc
    187   (cond-expand
    188     (windows  (foreign-lambda double "erfc" double) )
    189     (else     (foreign-lambda double "erfc" double) ) ) )
     177(define erf (foreign-lambda double "erf" double))
     178(define erfc (foreign-lambda double "erfc" double))
    190179
    191180;; Hyperbolic functions
     
    214203;; Euclidean distance function
    215204
    216 (define hypot
    217   (cond-expand
    218     (windows  (foreign-lambda double "hypot" double double) )
    219     (else     (foreign-lambda double "hypot" double double) ) ) )
     205(define hypot (foreign-lambda double "hypot" double double) )
    220206
    221207;; Gamma function
     
    243229;; Base-2 logarithm
    244230
    245 (define log2
    246   (cond-expand
    247     (windows  (foreign-lambda double "log2" double) )
    248     (else     (foreign-lambda double "log2" double) ) ) )
     231(define log2 (foreign-lambda double "log2" double) )
    249232
    250233;; Natural logarithm of 1+x accurate for very small x
    251234
    252 (define log1p
    253   (cond-expand
    254     (windows  (foreign-lambda double "log1p" double) )
    255     (else     (foreign-lambda double "log1p" double) ) ) )
     235(define log1p (foreign-lambda double "log1p" double) )
    256236
    257237;; Compute x * 2**n
     
    261241;; Efficiently compute x * 2**n
    262242
    263 (define scalbn
    264   (cond-expand
    265     (windows  (foreign-lambda double "scalbn" double integer) )
    266     (else     (foreign-lambda double "scalbn" double integer) ) ) )
     243(define scalbn (foreign-lambda double "scalbn" double integer) )
    267244
    268245;; Log function for base n
  • release/4/mathh/trunk/mathh.setup

    r35143 r35160  
    1212
    1313;* (The compiler option '-inline-global' causes problems; so no -O3+.)
    14 (setup-shared+static-extension-module (extension-name) (extension-version "3.3.2")
     14(setup-shared+static-extension-module (extension-name) (extension-version "3.3.3")
    1515  ;cannot be inline #1340
    1616  ;#:inline? #t
     
    1919  #:files '("mathh-constants.scm"))
    2020
    21 (setup-shared+static-extension-module 'mathh-consts (extension-version "3.3.2")
     21(setup-shared+static-extension-module 'mathh-consts (extension-version "3.3.3")
    2222  #:inline? #t
    2323  #:types? #t
     
    2727    -no-bound-checks -no-argc-checks -no-procedure-checks))
    2828
    29 (setup-shared+static-extension-module 'fp-utils (extension-version "3.3.2")
     29(setup-shared+static-extension-module 'fp-utils (extension-version "3.3.3")
    3030  #:inline? #t
    3131  #:types? #t
     
    3535    -no-procedure-checks))
    3636
    37 (setup-shared+static-extension-module 'fx-utils (extension-version "3.3.2")
     37(setup-shared+static-extension-module 'fx-utils (extension-version "3.3.3")
    3838  #:inline? #t
    3939  #:types? #t
Note: See TracChangeset for help on using the changeset viewer.