将货币值设置为 NAN、INF 或 -INF?

发布于 2024-11-29 23:57:12 字数 1503 浏览 3 评论 0原文

我想测试一些代码以确保它正确处理 NANINF-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);
  ...

转换 Double 时出现 EInvalidOp 无效浮点运算 异常> 将NAN 转换为货币

是否可以将NAN分配给货币

也许,将 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');
}

i want to test some code to make sure it handles NAN, INF and -INF inputs properly.

i know there exists functions that return NAN, INF and -INF, but as a Double:

unit IEEE754;
...
function NAN: Double;
function PositiveInfinity:  Double;
function NegativeInfinity:  Double;

Except in my case i need to test when a Currency is one of these three edge-case values. Unfortunatly you cannot convert any of these to a Double:

Test(NAN);

procedure Test(const Value: Currency);
  ...

There's an EInvalidOp Invalid floating point operation exception when converting a Double NAN to a Currency.

Is it possible to assign a NAN to a Currency?

Perhaps, rather than it being possible to assign a NAN to a Currency, it is instead not possible - and i can just ignore this edge case.

Can i ignore this edge case?

Is it possible to "Set a Currency value to NAN, INF or -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');
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

此生挚爱伱 2024-12-06 23:57:12

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

文档解释了货币是作为隐式比例为 10000 的 64 位整数实现的,并且可能值的范围是 -922337203685477.5808 到 922337203685477.5807。由于这涵盖了 64 位整数的整个范围,因此没有可用于像 NAN 或 INF 这样的标记值的位模式。

Currency is not an IEEE754 float type and does not have NAN or INF values.

The documentation explains that Currency is implemented as a 64 bit integer with implicit scale of 10000 and that the range of possible values is -922337203685477.5808 to 922337203685477.5807. Since this covers the full range of a 64 bit integer it follows that there are no bit patterns available for sentinel values like NAN or INF.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文