This is an automated email from the ASF dual-hosted git repository.
garydgregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git
The following commit(s) were added to refs/heads/master by this push:
new e79cea111 Performance: Short-circuit check based on pre-derived
candidate Double (#1628)
e79cea111 is described below
commit e79cea11136d4ee851bafc434efcb834946524f5
Author: AxC <[email protected]>
AuthorDate: Mon Apr 27 04:48:57 2026 +0530
Performance: Short-circuit check based on pre-derived candidate Double
(#1628)
Numeric identity pre-check for the heap-allocating
f.toString().equals(d.toString())
---
src/main/java/org/apache/commons/lang3/math/NumberUtils.java | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/main/java/org/apache/commons/lang3/math/NumberUtils.java
b/src/main/java/org/apache/commons/lang3/math/NumberUtils.java
index 92b363a72..d81cdae31 100644
--- a/src/main/java/org/apache/commons/lang3/math/NumberUtils.java
+++ b/src/main/java/org/apache/commons/lang3/math/NumberUtils.java
@@ -501,7 +501,8 @@ public static Number createNumber(final String str) {
try {
final Float f = createFloat(str);
final Double d = createDouble(str);
- if (!f.isInfinite() && !(f.floatValue() == 0.0F && !isZero(mant,
dec)) && f.toString().equals(d.toString())) {
+ if (!f.isInfinite() && !(f.floatValue() == 0.0F && !isZero(mant,
dec))
+ && ((double) d.floatValue() == d.doubleValue() ||
f.toString().equals(d.toString()))) {
return f;
}
if (!d.isInfinite() && !(d.doubleValue() == 0.0D && !isZero(mant,
dec))) {