瞎扯淡 Oj.dump 一个 NaN 会出现 PI

lithium4010 · December 01, 2016 · Last by quakewang replied at December 01, 2016 · 1878 hits

发现一个有趣的现象


# ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin14]
# oj (2.18.0)

2.3.0 :006 > Oj.dump({a: (0 / 0.to_f)})
=> "{\":a\":3.3e14159265358979323846}"

用超过上限的数字来表示 NaN,保证 dump 回来的数据能正常显示 NaN?哈哈哈哈

https://github.com/ohler55/oj/blob/cecfe196af51e8fc964cd6d9751e50724f1cb8bf/ext/oj/oj.h#L73

#define INF_VAL     "3.0e14159265358979323846"
#define NINF_VAL    "-3.0e14159265358979323846"
#define NAN_VAL     "3.3e14159265358979323846"
You need to Sign in before reply, if you don't have an account, please Sign up first.