我想测试一些代码,以确保它正确地处理NAN、INF和-INF输入。
我知道存在返回的函数 NAN,INF和-INF,但作为一个Double
unit IEEE754;
...
function NAN: Double;
function PositiveInfinity: Double;
function NegativeInfinity: Double;除了在我的情况下,我需要测试何时Currency是这三个边缘大小写值之一。不幸的是,您无法将其中任何一个转换为Double
Test(NAN);
procedure Test(const Value: Currency);
...当将EInvalidOp NAN转换为Currency时,存在一个无效的浮点操作异常。
是否可以将NAN分配给Currency
也许,不可能将NAN分配给Currency,而是而不是可能--我可以忽略这个边缘情况。
我能忽略这个边缘的案子吗?
是否有可能“将货币值设置为NAN、INF或-INF”?
{ David Heffernan says it's impossible for a currency to contain INF,-INF or NAN.
So there's no need to test for it.
http://stackoverflow.com/questions/7096966/set-a-currency-value-to-nan-inf-or-inf
//Handle NaN, where exponent is -32767
test(NAN, 'NAN');
//Handle +inf, where exponent is 32767 and Negative is true
test(PositiveInfinity, 'INF');
//Handle -inf, where expondent is 32767 and Negative is true
test(NegativeInfinity, '-INF');
}发布于 2011-08-17 17:32:36
货币不是IEEE754浮点类型,并且没有NAN或INF值。
文档解释说,货币是以64位整数的形式实现的,其隐式比例尺为10000,并且可能值的范围是-922337203685477.5808到922337203685477.5807。由于这涵盖了64位整数的全部范围,因此对于NAN或INF这样的前哨值没有可用的位模式。
https://stackoverflow.com/questions/7096966
复制相似问题