我正在将一些软件转换为使用fmt库,以前fmt库使用double-conversion
、iostream
和boost::format
的组合,输出的大多数数值是双精度浮点,我们进行了大量测试,检查无穷大、nan等极端情况。
我的问题是,使用fmt时,许多测试输出都变成了显示 negative-not-numbers:-nan
,这对我来说是一个毫无意义的概念。
我知道IEEE-754规范允许nan
的大量不同位表示,包括设置或清除符号位。但我想知道的是一个值是否为数字。一旦一个值为nan
,我不在乎是否有人试图对这个值求反,对nan
的任何运算结果都应该是nan
,负号不会增加任何有意义的值。
那么,在使用libfmt时,如何省略double
-nan
值上的负号呢?
1条答案
按热度按时间nimxete21#
我最终为双精度创建了一个 Package 类,并为它定义了一个自定义的
formatter
,这解决了我遇到的问题。