mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-09-18 02:08:09 +08:00
fix: fix serialization of inf/nan
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
// Distributed under the MIT License.
|
// Distributed under the MIT License.
|
||||||
#ifndef TOML11_SERIALIZER_HPP
|
#ifndef TOML11_SERIALIZER_HPP
|
||||||
#define TOML11_SERIALIZER_HPP
|
#define TOML11_SERIALIZER_HPP
|
||||||
|
#include <cmath>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
||||||
#include <limits>
|
#include <limits>
|
||||||
@@ -115,6 +116,29 @@ struct serializer
|
|||||||
}
|
}
|
||||||
std::string operator()(const floating_type f) const
|
std::string operator()(const floating_type f) const
|
||||||
{
|
{
|
||||||
|
if(std::isnan(f))
|
||||||
|
{
|
||||||
|
if(std::signbit(f))
|
||||||
|
{
|
||||||
|
return std::string("-nan");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return std::string("nan");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(!std::isfinite(f))
|
||||||
|
{
|
||||||
|
if(std::signbit(f))
|
||||||
|
{
|
||||||
|
return std::string("-inf");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return std::string("inf");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const auto fmt = "%.*g";
|
const auto fmt = "%.*g";
|
||||||
const auto bsz = std::snprintf(nullptr, 0, fmt, this->float_prec_, f);
|
const auto bsz = std::snprintf(nullptr, 0, fmt, this->float_prec_, f);
|
||||||
// +1 for null character(\0)
|
// +1 for null character(\0)
|
||||||
|
Reference in New Issue
Block a user