mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-03 12:21:23 +00:00
Add default NaN/Inf to C#, Java, Python (#5107)
* Add default NaN/Inf to C#, Java, Python * Python NaN/Inf test added * Remove MSVC2010/13 dependent code
This commit is contained in:
committed by
Wouter van Oortmerssen
parent
46208b1e91
commit
4fa4d36706
@@ -34,50 +34,15 @@ static std::string GeneratedFileName(const std::string &path,
|
||||
}
|
||||
|
||||
namespace cpp {
|
||||
class CppFloatConstantGenerator : public FloatConstantGenerator {
|
||||
protected:
|
||||
std::string Value(double v,
|
||||
const std::string &src) const FLATBUFFERS_OVERRIDE {
|
||||
(void)v;
|
||||
return src;
|
||||
};
|
||||
|
||||
std::string Value(float v,
|
||||
const std::string &src) const FLATBUFFERS_OVERRIDE {
|
||||
(void)v;
|
||||
return src + "f";
|
||||
}
|
||||
|
||||
std::string NaN(double v) const FLATBUFFERS_OVERRIDE {
|
||||
(void)v;
|
||||
return "std::numeric_limits<double>::quiet_NaN()";
|
||||
}
|
||||
std::string NaN(float v) const FLATBUFFERS_OVERRIDE {
|
||||
(void)v;
|
||||
return "std::numeric_limits<float>::quiet_NaN()";
|
||||
}
|
||||
|
||||
std::string Inf(double v) const FLATBUFFERS_OVERRIDE {
|
||||
if(v < 0)
|
||||
return "-std::numeric_limits<double>::infinity()";
|
||||
else
|
||||
return "std::numeric_limits<double>::infinity()";
|
||||
}
|
||||
|
||||
std::string Inf(float v) const FLATBUFFERS_OVERRIDE {
|
||||
if (v < 0)
|
||||
return "-std::numeric_limits<float>::infinity()";
|
||||
else
|
||||
return "std::numeric_limits<float>::infinity()";
|
||||
}
|
||||
};
|
||||
|
||||
class CppGenerator : public BaseGenerator {
|
||||
public:
|
||||
CppGenerator(const Parser &parser, const std::string &path,
|
||||
const std::string &file_name)
|
||||
: BaseGenerator(parser, path, file_name, "", "::"),
|
||||
cur_name_space_(nullptr) {
|
||||
cur_name_space_(nullptr),
|
||||
float_const_gen_("std::numeric_limits<double>::",
|
||||
"std::numeric_limits<float>::", "quiet_NaN()",
|
||||
"infinity()") {
|
||||
static const char * const keywords[] = {
|
||||
"alignas",
|
||||
"alignof",
|
||||
@@ -2785,7 +2750,7 @@ class CppGenerator : public BaseGenerator {
|
||||
cur_name_space_ = ns;
|
||||
}
|
||||
|
||||
const CppFloatConstantGenerator float_const_gen_;
|
||||
const TypedFloatConstantGenerator float_const_gen_;
|
||||
};
|
||||
|
||||
} // namespace cpp
|
||||
|
||||
Reference in New Issue
Block a user