What does floating point error -1.#J mean?

Recently, sometimes (rarely) when we export data from our application, the export log contains float values that look like "-1.#J". I haven't been able to reproduce it so I don't know what the float looks like in binary, or how Visual Studio displays it.

I tried looking at the source code for printf, but didn't find anything (not 100% sure I looked at the right version though...).

I've tried googling but google throws away any #, it seems. And I can't find any lists of float errors.

link | improve this question

 
feedback

1 Answer

up vote 14 down vote accepted

It can be either negative infinity or NaN (not a number). Due to the formatting on the field printf does not differentiate between them.

I tried the following code in Visual Studio 2008:

double a = 0.0;
printf("%.3g\n", 1.0 / a);  // +inf
printf("%.3g\n", -1.0 / a); // -inf
printf("%.3g\n", a / a);    //  NaN

which results in the following output:

1.#J
-1.#J
-1.#J

removing the .3 formatting specifier gives:

1.#INF
-1.#INF
-1.#IND

so it's clear 0/0 gives NaN and -1/0 gives negative infinity (NaN, -inf and +inf are the only "erroneous" floating point numbers, if I recall correctly)


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值