在线咨询
eetop公众号 创芯大讲堂 创芯人才网
切换到宽版

EETOP 创芯网论坛 (原名:电子顶级开发网)

手机号码,快捷登录

手机号码,快捷登录

找回密码

  登录   注册  

快捷导航
搜帖子
查看: 246|回复: 2

[求助] 新人求助,关于判断式

[复制链接]
发表于 2024-8-13 16:35:37 | 显示全部楼层 |阅读模式
20资产
新人在自学skill语句中,尝试写了一个脚本,正式使用时出了问题,检查下来发现是判断式这里出了问题,但不清楚为什么,希望大佬能指点一下。


问题范例:
A=1.6
A-0.6==1.0;判断为t
A-1.0==0.6;判断为nil
B=2.0
B-1.2==0.8;判断为t
B-1.8==0.2;判断为nil


最佳答案

查看完整内容

SKILL Language User Guide.pdf的第128页Floating_Point Issues中写了这个问题,原文如下: Because IEEE floating-point numbers use what are essentially binary (base 2) fractions to represent real numbers, some functions that operate on floating-point numbers yield unexpected (and incorrect) results. There are some floating-point numbers that the computer cannot represent exactly as binary fractions. In ...
发表于 2024-8-13 16:35:38 | 显示全部楼层
SKILL Language User Guide.pdf的第128页Floating_Point Issues中写了这个问题,原文如下:
Because IEEE floating-point numbers use what are essentially binary (base 2) fractions to represent real numbers, some functions that operate on floating-point numbers yield unexpected (and incorrect) results. There are some floating-point numbers that the computer cannot represent exactly as binary fractions. In these cases, the computer uses a binary (base 2) floating-point number to approximate your decimal (base 10) floating-point number. These approximations can lead to incorrect results for some functions that operate on floating-point numbers.

翻译后的意思如下:
因为IEEE浮点数本质上使用二进制(以2为基数)分数来表示实数,所以一些对浮点数进行操作的函数会产生意想不到的(和不正确的)结果。有些浮点数计算机不能精确地表示为二进制分数。在这些情况下,计算机使用二进制(以2为基数)浮点数来近似您的十进制(以10为基数)浮点数。对于某些操作浮点数的函数,这些近似可能导致不正确的结果。
发表于 2024-8-13 16:48:18 | 显示全部楼层
好像和浮点类型数据的存储精度有关,我上次也出错了。
最好用 A-1.6<0.001 这样来判断
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

站长推荐 上一条 /2 下一条

小黑屋| 手机版| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-9-21 10:56 , Processed in 0.018137 second(s), 6 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
快速回复 返回顶部 返回列表