File tree Expand file tree Collapse file tree 1 file changed +13
-3
lines changed
math-lib/math/private/bigfloat Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -687,7 +687,6 @@ There's no reason to allocate new limbs for an _mpfr without changing its precis
687687 [bfbesy0 'mpfr_y0 ]
688688 [bfbesy1 'mpfr_y1 ]
689689 [bfrint 'mpfr_rint ]
690- [bfround 'mpfr_rint_roundeven ]
691690 [bffloor 'mpfr_rint_floor ]
692691 [bfceiling 'mpfr_rint_ceil ]
693692 [bftruncate 'mpfr_rint_trunc ]
@@ -702,9 +701,20 @@ There's no reason to allocate new limbs for an _mpfr without changing its precis
702701 [(= 0 (bigfloat-signbit x)) (force 1.bf)]
703702 [else (force -1.bf)]))
704703
705- (provide bfsgn)
704+ (define (bfround x)
705+ (if (>= (bigfloat-exponent x) 0 )
706+ ;; In this case, `x` is already an integer, so no rounding needs
707+ ;; to be performed; we use bfcopy to change precision while
708+ ;; respecting rounding mode
709+ (bfcopy x)
710+ ;; In this case, `x` is known not to be near infinity, so
711+ ;; `bfrint` will do the right thing.
712+ (parameterize ([bf-rounding-mode 'nearest ])
713+ (bfrint x))))
714+
715+ (provide bfsgn bfround)
706716(begin-for-syntax
707- (set! 1ary-funs (list* #'bfsgn 1ary-funs)))
717+ (set! 1ary-funs (list* #'bfsgn #'bfround 1ary-funs)))
708718
709719(define mpfr-fac-ui (get-mpfr-fun 'mpfr_fac_ui (_fun _mpfr-pointer _ulong _rnd_t -> _int)))
710720
You can’t perform that action at this time.
0 commit comments