mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-11 15:37:27 +00:00
Fix handling of +/-inf defaults in TS/rust/go/dart codegen (#7588)
+/-inf were not being handled, and so invalid typescript was being generated when a float/double had an infinite default value. NaN was being handled correctly. Co-authored-by: Derek Bailey <derekbailey@google.com> Co-authored-by: Casper <casperneo@uchicago.edu>
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
|
||||
@@ -454,9 +455,16 @@ class TsGenerator : public BaseGenerator {
|
||||
return "BigInt('" + value.constant + "')";
|
||||
}
|
||||
|
||||
default:
|
||||
if (value.constant == "nan") { return "NaN"; }
|
||||
default: {
|
||||
if (StringIsFlatbufferNan(value.constant)) {
|
||||
return "NaN";
|
||||
} else if (StringIsFlatbufferPositiveInfinity(value.constant)) {
|
||||
return "Infinity";
|
||||
} else if (StringIsFlatbufferNegativeInfinity(value.constant)) {
|
||||
return "-Infinity";
|
||||
}
|
||||
return value.constant;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user