diff --git a/collects/math/private/bigfloat/mpfr.rkt b/collects/math/private/bigfloat/mpfr.rkt index d73f6cc3d5..d7b7c82472 100644 --- a/collects/math/private/bigfloat/mpfr.rkt +++ b/collects/math/private/bigfloat/mpfr.rkt @@ -44,7 +44,18 @@ string->bigfloat ;; Main constructor bf - bigfloat-deserialize-info) + bigfloat-deserialize-info + ;; Low-level stuff + mpfr-lib + get-mpfr-fun + _rnd_t + _prec_t + _sign_t + _exp_t + _mpfr_size_limb_t + _mpfr + _mpfr-pointer + (struct-out mpfr)) ;; Arithmetic, comparison, and other functions are provided by the macros that create them diff --git a/collects/tests/racket/stress/mpfr-ffi-call-vs-racket.rkt b/collects/tests/racket/stress/mpfr-ffi-call-vs-racket.rkt new file mode 100644 index 0000000000..0e9c704ccd --- /dev/null +++ b/collects/tests/racket/stress/mpfr-ffi-call-vs-racket.rkt @@ -0,0 +1,44 @@ +#lang racket/base + +(require ffi/unsafe + tests/stress + math/private/bigfloat/mpfr) + +(define mpfr-get-exp (get-mpfr-fun 'mpfr_get_exp (_fun _mpfr-pointer -> _exp_t))) +(define mpfr-get-prec (get-mpfr-fun 'mpfr_get_prec (_fun _mpfr-pointer -> _prec_t))) +(define mpfr-get-signbit (get-mpfr-fun 'mpfr_signbit (_fun _mpfr-pointer -> _int))) + +(define (mpfr-signbit x) + (if ((mpfr-sign x) . < . 0) 1 0)) + +(define n 1000000) + +(let ([x (bf 2)]) + (stress + 20 + ["mpfr-get-prec (FFI accessor)" + (for ([_ (in-range n)]) + (mpfr-get-prec x))] + ["mpfr-prec (Racket accessor)" + (for ([_ (in-range n)]) + (mpfr-prec x))])) + +(let ([x (bf 2)]) + (stress + 20 + ["mpfr-get-exp (FFI accessor)" + (for ([_ (in-range n)]) + (mpfr-get-exp x))] + ["mpfr-exp (Racket accessor)" + (for ([_ (in-range n)]) + (mpfr-exp x))])) + +(let ([x (bf 2)]) + (stress + 20 + ["mpfr-get-signbit (FFI accessor)" + (for ([_ (in-range n)]) + (mpfr-get-signbit x))] + ["mpfr-signbit (Racket accessor)" + (for ([_ (in-range n)]) + (mpfr-signbit x))]))