1

我想测试一些代码以确保它可以正确处理和NAN输入。INF-INF

我知道存在返回 和的函数NAN,但作为:INF-INFDouble

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 NANCurrency

是否可以将 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');
}
4

1 回答 1

11

货币不是 IEEE754 浮点类型,并且没有 NAN 或 INF 值。

文档解释说 Currency被实现为 64 位整数,隐含比例为 10000,可能值的范围是 -922337203685477.5808 到 922337203685477.5807。由于这涵盖了 64 位整数的全部范围,因此没有可用于诸如 NAN 或 INF 之类的标记值的位模式。

于 2011-08-17T17:32:36.540 回答