v0.0.380 exerr properly handle inf and nan floats
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 3m8s

This commit is contained in:
2024-01-22 12:33:41 +01:00
parent b9d0348735
commit 890e16241d
2 changed files with 25 additions and 2 deletions

View File

@@ -9,6 +9,7 @@ import (
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
"gogs.mikescher.com/BlackForestBytes/goext/langext"
"math"
"strconv"
"strings"
"time"
@@ -667,6 +668,28 @@ func (v MetaValue) rawValueForJson() any {
}
return v.Value.(EnumWrap).ValueString
}
if v.DataType == MDTFloat32 {
if math.IsNaN(float64(v.Value.(float32))) {
return "float64::NaN"
} else if math.IsInf(float64(v.Value.(float32)), +1) {
return "float64::+inf"
} else if math.IsInf(float64(v.Value.(float32)), -1) {
return "float64::-inf"
} else {
return v.Value
}
}
if v.DataType == MDTFloat64 {
if math.IsNaN(v.Value.(float64)) {
return "float64::NaN"
} else if math.IsInf(v.Value.(float64), +1) {
return "float64::+inf"
} else if math.IsInf(v.Value.(float64), -1) {
return "float64::-inf"
} else {
return v.Value
}
}
return v.Value
}