You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
1.6 KiB
35 lines
1.6 KiB
4 years ago
|
From 91d852fe2c6a6bf51287a1ad95ef6e21ffa9d261 Mon Sep 17 00:00:00 2001
|
||
|
From: Eugene Kenny <elkenny@gmail.com>
|
||
|
Date: Fri, 1 Jan 2021 16:05:37 +0000
|
||
|
Subject: [PATCH] Fix rounding NaN and Infinity on newer BigDecimal
|
||
|
|
||
|
Since BigDecimal 2.0.3, BigDecimal#round returns an integer if the
|
||
|
requested precision is less than 1:
|
||
|
https://github.com/ruby/bigdecimal/commit/e8fc98050167fd943574609988b8754414e0a7c1
|
||
|
|
||
|
NaN and Infinity cannot be represented as an integer, so rounding these
|
||
|
values now raises a FloatDomainError. This is a regression of the fix in
|
||
|
081a3963ea2aab617a92874d7ef59ce98eee6a64.
|
||
|
|
||
|
Specifying the rounding mode restores the previous behaviour.
|
||
|
|
||
|
This isn't a problem on master or 6-1-stable, as the rounding mode is
|
||
|
always specified there since 7905bdfd8b2ae50319cd7a9a74ee1f8c865d648d.
|
||
|
---
|
||
|
.../lib/active_support/number_helper/rounding_helper.rb | 2 +-
|
||
|
1 file changed, 1 insertion(+), 1 deletion(-)
|
||
|
|
||
|
diff --git a/activesupport/lib/active_support/number_helper/rounding_helper.rb b/activesupport/lib/active_support/number_helper/rounding_helper.rb
|
||
|
index 2ad8d49c4edb..7f7242f8651a 100644
|
||
|
--- a/activesupport/lib/active_support/number_helper/rounding_helper.rb
|
||
|
+++ b/activesupport/lib/active_support/number_helper/rounding_helper.rb
|
||
|
@@ -26,7 +26,7 @@ def digit_count(number)
|
||
|
|
||
|
private
|
||
|
def round_without_significant(number)
|
||
|
- number = number.round(precision)
|
||
|
+ number = number.round(precision, BigDecimal.mode(BigDecimal::ROUND_MODE))
|
||
|
number = number.to_i if precision == 0 && number.finite?
|
||
|
number = number.abs if number.zero? # prevent showing negative zeros
|
||
|
number
|