【问题标题】:Matlab/Octave addition, losing digits of precisionMatlab / Octave加法,丢失精度
【发布时间】:2012-12-14 21:55:59
【问题描述】:

在 Matlab/octave 中,当我添加两个数字时,我丢失了一些数字。

>>> 23.0 + 0.65850
ans =  23.659

如何取回 23.65850 的双精度值?

【问题讨论】:

    标签: matlab octave


    【解决方案1】:

    为了显示目的,对数字进行了四舍五入。如果您想更改它,请查看format 命令。

    octave> 23 + 0.65850
    ans =  23.659
    octave> format free
    octave> 23 + 0.65850
    ans = 23.7
    octave> format long g
    octave> 23 + 0.65850
    ans =              23.6585
    

    查看help format 了解其他选项,但请记住,这会影响显示。您不会失去任何精度。

    【讨论】:

    • 在计算过程中正在进行舍入...只是没有显示的字符串所暗示的那么多。
    • @BenVoigt 是的,但这来自使用双精度。你知道我的意思;)
    猜你喜欢
    • 2014-10-03
    • 2013-06-17
    • 2012-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-07
    • 1970-01-01
    相关资源
    最近更新 更多