有没有“正常"?Mathematica 中的 EqualQ 函数? [英] Is there a "normal" EqualQ function in Mathematica?

查看:15
本文介绍了有没有“正常"?Mathematica 中的 EqualQ 函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Equal 的文档页面上,我们读到

On the documentation page for Equal we read that

与机器的近似数字考虑精度或更高如果它们最多不同,则相等最后七位二进制数字(大约最后两位十进制数字).

Approximate numbers with machine precision or higher are considered equal if they differ in at most their last seven binary digits (roughly their last two decimal digits).

以下是示例(32 位系统;对于 64 位系统,在中间添加更多零):

Here are examples (32 bit system; for 64 bit system add some more zeros in the middle):

In[1]:= 1.0000000000000021 == 1.0000000000000022
1.0000000000000021 === 1.0000000000000022

Out[1]= True

Out[2]= True

我想知道 Mathematica 中的 Equal 函数是否有一个正常"的模拟,它不会去掉最后 7 个二进制数字?

I'm wondering is there a "normal" analog of the Equal function in Mathematica that does not drop last 7 binary digits?

推荐答案

In[12]:= MyEqual[x_, y_] := Order[x, y] == 0

In[13]:= MyEqual[1.0000000000000021, 1.0000000000000022]

Out[13]= False

In[14]:= MyEqual[1.0000000000000021, 1.0000000000000021]

Out[14]= True

这会测试两个对象是否相同,因为 1.0000000000000021 和 1.000000000000002100 的精度不同,它们不会被视为相同.

This tests if two object are identical, since 1.0000000000000021 and 1.000000000000002100 differs in precision they won't be considered as identical.

这篇关于有没有“正常"?Mathematica 中的 EqualQ 函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆