floor

RoundTo 及其相关的一些内容总结

帅比萌擦擦* 提交于 2019-12-02 16:25:04
1. Round (四舍六入五留双) 功能说明:对一个实数进行四舍五入。(按照银行家算法) 例: var i, j: Integer; begin i := Round(1.5); // i等于2 j := Round(2.5); // j等于2 end; 在 Delphi 中使用Round函数得到的答案有时与我们所预期的会不太一样:采用的是四舍六入五留双。即当舍或入位大于或小于五时按四舍五入来处理 ,而当舍或入位等于五时,就要看前面一位是什么,根据奇进偶不进,它总是返回一个偶数值。 例: i:= Round(11.5)//i等于12 i:= Round(10.5)//i等于10 这种Round其实是按照银行家算法,统计学上一般都用这种算法,比传统的"四舍五入"要科学。 如果要使用传统的"四舍五入"方法,可以使用下面函数: function RoundClassic(R: Real) 2. trunc (取得X的整数部分) 如: trunc (-123.55)=-123, floor(123.55)=123 3. ceil (取得大于等于X的最小的整数) 如:ceil(-123.55)=-123, ceil(123.15)=124 4. floor (取得小于等于X的最大的整数) 如:floor(-123.55)=-124,floor(123.55)=123 5.RoundTo

Why am I getting unexpected output when using floor with pow?

為{幸葍}努か 提交于 2019-12-02 07:27:06
So, I ran this code on my code blocks: #include<iostream> #include<cmath> using namespace std; int main() { int a; a=pow(10,9); cout<<a<<endl; a=ceil(pow(10,9)); cout<<a<<endl; a=floor(pow(10,9)); cout<<a<<endl; return 0; } I got the output as: 999999999 100000000 100000000 1st output was not 10^9 due to truncation effect,which means that pow(10,9) was something like 999999999.99999.., but then how come floor of this thing is 1000000000 ?? Actually, the maximum value for int is 2,147,483,647, therefore there should be no overflow or truncation (it's an int ). And my output is exactly:

Why am I getting unexpected output when using floor with pow?

元气小坏坏 提交于 2019-12-02 07:20:34
问题 So, I ran this code on my code blocks: #include<iostream> #include<cmath> using namespace std; int main() { int a; a=pow(10,9); cout<<a<<endl; a=ceil(pow(10,9)); cout<<a<<endl; a=floor(pow(10,9)); cout<<a<<endl; return 0; } I got the output as: 999999999 100000000 100000000 1st output was not 10^9 due to truncation effect,which means that pow(10,9) was something like 999999999.99999.., but then how come floor of this thing is 1000000000 ?? 回答1: Actually, the maximum value for int is 2,147,483

Objective-C: Flooring to 3 decimals correctly

好久不见. 提交于 2019-12-02 04:51:06
问题 I am trying to floor a float value to the third decimal. For example, the value 2.56976 shall be 2.569 not 2.570. I searched and found answers like these: floor double by decimal place Such answers are not accurate. For example the code: double value = (double)((unsigned int)(value * (double)placed)) / (double)placed can return the value - 1 and this is not correct. The multiplication of value and placed value * (double)placed) could introduce something like: 2100.999999996. When changed to

math_ops.floor equivalent in Keras

戏子无情 提交于 2019-12-01 21:21:19
I'm trying to implement a custom layer in Keras where I need to convert a tensor of floats [a, 1+a) to a binary tensor for masking. I can see that Tensorflow has a floor function that can do that, but Keras doesn't seem to have it in keras.backend . Any idea how I can do this? As requested by OP, I will mention the answer I gave in my comment and elaborate more: Short answer: you won't encounter any major problems if you use tf.floor() . Long answer: Using Keras backend functions (i.e. keras.backend.* ) is necessary in those cases when 1) there is a need to pre-process or augment the argument

Function int() rounding towards negative infinity (floor) or zero?

三世轮回 提交于 2019-12-01 18:26:12
问题 I see Why is -1/2 evaluated to 0 in C++, but -1 in Python? says integer division rounds towards infinity in Python, namely, floor is applied to the result. I thought int(value) would also do something like floor , while I get int(-1.5) == -1 in practice, which was expected to be -2 in my mind. So question is: why rules are inconsistent between integer division and function int() ? Is there any reasonable explanation? 回答1: int() removes the decimal component; it doesn't do any rounding. From

Function int() rounding towards negative infinity (floor) or zero?

谁说胖子不能爱 提交于 2019-12-01 18:20:37
I see Why is -1/2 evaluated to 0 in C++, but -1 in Python? says integer division rounds towards infinity in Python, namely, floor is applied to the result. I thought int(value) would also do something like floor , while I get int(-1.5) == -1 in practice, which was expected to be -2 in my mind. So question is: why rules are inconsistent between integer division and function int() ? Is there any reasonable explanation? int() removes the decimal component; it doesn't do any rounding. From the documentation : If x is floating point, the conversion truncates towards zero. For turning a float into

Representable result of floor() and ceil()

我是研究僧i 提交于 2019-12-01 17:35:48
For an arbitrary value 'v' of a floating point type (float/double/long double), does C89 guarantee that the mathematically exact integer result of floor(v) and ceil(v) is a representable value of the type of 'v'? Does any of the later C or C++ standards guarantee this? Does IEEE 754 guarantee this? This is guaranteed by the construction of IEEE-754 numbers. (To be clear: C does not guarantee IEEE-754, but the following analysis holds for all other floating-point formats with which I am familiar as well; the crucial property is that all sufficiently large numbers in the format are integers).

Representable result of floor() and ceil()

一世执手 提交于 2019-12-01 16:23:51
问题 For an arbitrary value 'v' of a floating point type (float/double/long double), does C89 guarantee that the mathematically exact integer result of floor(v) and ceil(v) is a representable value of the type of 'v'? Does any of the later C or C++ standards guarantee this? Does IEEE 754 guarantee this? 回答1: This is guaranteed by the construction of IEEE-754 numbers. (To be clear: C does not guarantee IEEE-754, but the following analysis holds for all other floating-point formats with which I am

Rounding a MYSQL datetime to earliest 15 minute interval in milliseconds (PHP)

故事扮演 提交于 2019-12-01 11:06:23
I'm fetching a datetime from MYSQL which looks like: 2010-08-11 11:18:28 I need to convert it into the "floor" or the earliest 15 minute interval and output in milliseconds for another function. So, this case would be: 2010-08-11 11:15:00 in milliseconds Whoops! Sorry - need to clarify - I need code that will transform it into milliseconds WITHIN php! Doing a timing test revealed the following: $time_start = microtime(true); for($i=0;$i<10000;$i++) floor(strtotime('2010-08-11 23:59:59')/(60*15))*60*15*1000; $time_end = microtime(true); echo 'time taken = '.($time_end - $time_start); time taken