From 890e16241d0724aa8a64d65be354eb7f48fa6e66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Mon, 22 Jan 2024 12:33:41 +0100 Subject: [PATCH] v0.0.380 exerr properly handle inf and nan floats --- exerr/meta.go | 23 +++++++++++++++++++++++ goextVersion.go | 4 ++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/exerr/meta.go b/exerr/meta.go index ea591d8..9279f52 100644 --- a/exerr/meta.go +++ b/exerr/meta.go @@ -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 } diff --git a/goextVersion.go b/goextVersion.go index 8d8ffdf..0378768 100644 --- a/goextVersion.go +++ b/goextVersion.go @@ -1,5 +1,5 @@ package goext -const GoextVersion = "0.0.379" +const GoextVersion = "0.0.380" -const GoextVersionTimestamp = "2024-01-19T17:30:20+0100" +const GoextVersionTimestamp = "2024-01-22T12:33:41+0100"