×

Loading...

Topic

This topic has been archived. It cannot be replied.
  • 工作学习 / 学科技术 / 不跑程序, 能看出width/high*2的结果吗?
    var high=1
    var width =1
    for ( i in 1..100000000) {
    width = 1 / high + width
    high = 1 / width + high
    }
    print("width/high="+width/high*2)
    • width/high=2
      • 误差有点大。
    • I'm afraid that it's not predictable.
      • 这个跑一下就知道了
    • c# 7.0 version
      private static void Test()
      {
      System.Diagnostics.Debug.WriteLine(F(1) * 2);
      double F(int i) { return i > 1000 ? 0 : 1 + i / (2.0 * i + 1) * F(i + 1); }
      }
      • 这是7.0的新语法?函数里面可以定义函数?
        • like js, eh?
          • 用了用c# 7,很好,已经不想再用老版本了,除了这个嵌套函数,那个增强型的tuple和deconstructors太好用了