我想测试一些代码以确保它可以正确处理和NAN
输入。INF
-INF
我知道存在返回 和的函数NAN
,但作为:INF
-INF
Double
unit IEEE754;
...
function NAN: Double;
function PositiveInfinity: Double;
function NegativeInfinity: Double;
除了在我的情况下,我需要测试 a 何时Currency
是这三个边缘情况值之一。不幸的是,您不能将其中任何一个转换为Double
:
Test(NAN);
procedure Test(const Value: Currency);
...
将 a 转换为 a时出现EInvalidOp
Invalid floating point operation异常。Double
NAN
Currency
是否可以将 a 分配NAN
给 a Currency
?
也许,不是可以将 a 分配NAN
给 a 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');
}