Merge branch 'redboltz/add_integer_to_float_conv'

This commit is contained in:
Nobuyuki Kubota
2014-02-28 15:53:05 +09:00
2 changed files with 78 additions and 4 deletions
+24 -4
View File
@@ -29,8 +29,18 @@ namespace msgpack {
inline float& operator>> (object o, float& v)
{
if(o.type != type::DOUBLE) { throw type_error(); }
v = (float)o.via.dec;
if(o.type == type::DOUBLE) {
v = (float)o.via.dec;
}
else if (o.type == type::POSITIVE_INTEGER) {
v = (float)o.via.u64;
}
else if (o.type == type::NEGATIVE_INTEGER) {
v = (float)o.via.i64;
}
else {
throw type_error();
}
return v;
}
@@ -44,8 +54,18 @@ inline packer<Stream>& operator<< (packer<Stream>& o, const float& v)
inline double& operator>> (object o, double& v)
{
if(o.type != type::DOUBLE) { throw type_error(); }
v = o.via.dec;
if(o.type == type::DOUBLE) {
v = o.via.dec;
}
else if (o.type == type::POSITIVE_INTEGER) {
v = (double)o.via.u64;
}
else if (o.type == type::NEGATIVE_INTEGER) {
v = (double)o.via.i64;
}
else {
throw type_error();
}
return v;
}