8

cpp 浮点的 ceil 计算和其它语言不一致的问题

 3 years ago
source link: https://www.v2ex.com/t/846153
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

V2EX  ›  C++

cpp 浮点的 ceil 计算和其它语言不一致的问题

  dusu · 13 小时 25 分钟前 · 618 次点击

各位大佬,最近在学 c++11 ,代码如下:

#include <iostream>
#include <math.h>

using namespace std;

int64_t random(int64_t seed){
    uint64_t result;
    result = (seed * 33 + 49297) % 23680;
    result = ceil((result * 10000000) / 23680);
    return result;
}


int main(){
    cout << random(1) << endl;
}
831925
   var seed = 1;
   result = (seed * 33 + 49297) % 23680;
   result = Math.ceil((result * 10000000) / 23680);
   console.log(result);

试了几个语言都是输出:

831926

c++ 结果如果是偶数的时候正常

出问题的结果都在奇数上

请问要怎么调整才能达到输出 js 的结果?

请大佬们赐教


Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK