代码之家  ›  专栏  ›  技术社区  ›  davidhartman00

除以一类数就是无穷大?

  •  3
  • davidhartman00  · 技术社区  · 7 年前

    对不起,这是一个明显的问题。我将两个变量相除,得到无穷大。以下是详细信息:

    typeof a //'number'
    typeof b //'number'
    typeof (a-b) //'number'
    typeof ((a-b)/(b)) //'number'
         a - b = xxx.xxxxx //this works
         (a - b)/b = Infinity
    

    a and b are five decimal places (XXX.XXXXX)
    // the variables are generated from ....
    var z = document.getElementById('foo').getBoundingClientRect()
    var y = document.getElementById('bar').getBoundingClientRect()
    var a = z.x
    var b = y.x
    

    foo bar 是一张桌子 a 在函数外部生成 b 在函数内部从 .on('scroll', ....)

    <div id="foo">
      <table id='bar'>
      </table>
    </div>
    

    我假设我的问题来自 typof = 'number' .

    2 回复  |  直到 7 年前
        1
  •  5
  •   Ori Drori    7 年前

    这是因为 b

    var a = 5
    var b = 0
    
    console.log('a ', typeof a);
    console.log('b ', typeof b);
    console.log('(a-b)/(b) ', (a-b)/(b))
    console.log('(a - b)/b ', (a - b)/b)
    console.log('typeof Infinity ', typeof Infinity)
        2
  •  1
  •   ivan.posokhin    7 年前

    也许,你除以零。正当

    enter image description here