

cpp 浮点的 ceil 计算和其它语言不一致的问题
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.

各位大佬,最近在学 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
-
22
关于 js 中的浮点计算by.陈蔓青2018-3-21😄 阅读本文需要的:能将十进制的整数或小数换算成二进制且知道原理知道原码补码反码,且掌握二进制的加减有好奇心有耐心...
-
9
浮点计算误差集累2012-06-05同一个函数,即使用递归和非递归两种形式实现,其计算结果都可能不相同。比如计算 1+e2+e3+…+endouble f(int n) { if(n == 0) return exp(0); else...
-
10
Java Math.ceil() Method with Examples Oct 12, 2019 · 2 mins read The java....
-
6
padfoot1717's blog
-
8
Copy link Contributor clarfonthey
-
12
Mr.Feng BlogNLP、深度学习、机器学习、Python、Gofloor、ceil、round、trunc函数都是什么?日常编程中,你是否也遇到过取值问题时面对这样的函数floor、ceil、ro...
-
7
Rounding in Java – Math.Round, Math.Floor, Math.CeilWe have decimal values in java, but sometimes there is a need to round them. It is important to remember which function should be used according to the requirements. So In...
-
29
1. Quartet Sampling(QS)methodQuartet Sampling(QS)是为系统发育树量化分支的支持率的一种方法,用于区分植物系统发育树上的强烈拓扑冲突和信息不足(缺乏支持)导致的支持率低,即区分强冲突(不一致)和弱支持...
-
6
Benjamin007's blog Ceil and fl...
-
8
_BAD_'s blog Divide n people into ce...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK