我无法理解为什么这会抛出对"floor"的未定义引用 ":
double curr_time = (double)time(NULL);
return floor(curr_time);
Run Code Online (Sandbox Code Playgroud)
难道它没有被加倍,这是什么楼层收到?
computerTotal = (int) Math.ceil(Math.random() * 21);
Run Code Online (Sandbox Code Playgroud)
有人可以告诉我如何获得16 - 21随机数我在尝试实现Math.floor函数时不断出错...正如你所看到的,我不太擅长将函数放入函数中.
非常感谢!
我非常中级.我知道有更快的方法来解决这个项目欧拉问题,但这是我提出的方式,它应该仍然有效,对吧?我知道这个问题不是很具体,但我发现很难解决一个我不知道的问题.任何帮助表示赞赏:(
#include <iostream>
#include <math.h> //declare floor
using namespace std;
int main()
{
cout << "What number would you like to find the sum of all multiples of 5 and 3?"<<endl;
int n;
int sum = 0;
cin >> n;
for(int x = 1; x < n; x = x + 1){
float f = x/5; //divides every number from 0 to n-1 (intended to be 1000) by 5.
float t = x/3;
if(floor(f) == f){ //checks to see if …
Run Code Online (Sandbox Code Playgroud) 我正在使用Python 2.7.13
我有这个简单的代码:
import math
a = [1,3,9,10,11,56,99,100,101,106,555,998,999,1000,1001,1102,9999,10000,10001,10002]
for i in a:
print "%d : log : %f / floor : %f / int : %d" %(i, math.log(i,10), math.floor(math.log(i,10)), int(math.log(i,10)))
Run Code Online (Sandbox Code Playgroud)
我想尝试不同数字的日志函数,看看当我在结果上使用floor函数或将其转换为整数时会发生什么
输出是:
1 : log : 0.000000 / floor : 0.000000 / int : 0
3 : log : 0.477121 / floor : 0.000000 / int : 0
9 : log : 0.954243 / floor : 0.000000 / int : 0
10 : log : 1.000000 / floor : 1.000000 …
Run Code Online (Sandbox Code Playgroud) 所以我有一列从 10 到 100 的值,我希望所有这些值都四舍五入到最接近的 10。诀窍是我希望它总是四舍五入。例如,55 将变成 50 而不是 60。我想会为此实现 floor,但是当我尝试 floor 时,它只返回相同的值而不改变。
x
10
15
20
27
30
34
Run Code Online (Sandbox Code Playgroud)
等等...
我想要的是:
x
10
10
20
20
30
30
Run Code Online (Sandbox Code Playgroud)
我试过的:
data$x <- floor(data$x)
Run Code Online (Sandbox Code Playgroud)
这只给了我完全相同的值。
我一直在研究用 编写的公差计算代码Double
,有精度和舍入问题我决定继续BigDecimal
考虑它更精确并且不太可能遇到舍入问题。在计算中,一段代码在分割值时使用Math.floor()
和Math.Ceil
。
奇怪的观察结果,ROUNDING_MODE.floor
并且ceil
在使用 时实际上并不适用BigDecimal
,这是最小的可重现示例。
Double doubleFloor = Math.floor(5.5/1.0);
Double doubleCeil = Math.ceil(5.5/1.0);
System.out.println(doubleFloor);
System.out.println(doubleCeil);
BigDecimal bigDecimalFloor = BigDecimal.valueOf(5.5).divide(BigDecimal.ONE,1,RoundingMode.FLOOR);
BigDecimal bigDecimalCeil = BigDecimal.valueOf(5.5).divide(BigDecimal.ONE,1,RoundingMode.CEILING);
System.out.println(bigDecimalFloor);
System.out.println(bigDecimalCeil);
Run Code Online (Sandbox Code Playgroud)
我希望为这么小的除法打印相同的值,但是我得到以下结果,floor 和 ceil 似乎没有按预期计算。
5.0
6.0
5.5
5.5
Run Code Online (Sandbox Code Playgroud)
我错过了什么。?
先感谢您
我想要floor()
下一个特定数字(不是数字,而是实际值)。例如,对于年份列表:
valid_years = c(1990,2000,2006,2012,2018) # values to round to ("snap")
input = c(1990, 1991, 1992, 1993, 2000, 2001, 2002, 2006, 2007, 2016, 2020)
output = c(1990, 1990, 1990, 1990, 2000, 2000, 2000, 2006, 2006, 2012, 2018)
Run Code Online (Sandbox Code Playgroud)
低于(或在ceil()
高于指定值的情况下)输入的行为对我来说并不重要。在我的情况下,一个好的行为是捕捉到 中的最低值valid_years
,但这对我来说并不重要。
我知道我可以用 if-then-else (eg if(x < 2006) x = 2000 else if(x < 2012) x = 2006 ...
)来实现这一点,但我相信有更优雅的方法来解决这个问题。
我浏览了许多“R 中的舍入”问题,但尽管有许多措辞相似的问题,但都没有找到答案,这些问题都有其独特的(不同)目标:例如,四舍五入到特定的小数步长, 四舍五入到某个范围内的任意数字或条件舍入。
如何制作一个功能,使所有数字的地板数量为18?
例:
3 => 0
17 => 0
19 => 18
43 => 36
69 => 54
Run Code Online (Sandbox Code Playgroud)
谢谢.
我正在寻找C#中floor(x)的实现,以便它与C++版本匹配.
floor of 2.3 is 2.0
floor of 3.8 is 3.0
floor of -2.3 is -3.0
floor of -3.8 is -4.0
Run Code Online (Sandbox Code Playgroud)
由于C++审阅者将检查我的代码,floor
在C#中哪些实现是合理的,这样他就不会拉出他的(最后剩下的)头发?
我正在做我的作业以实现一个C程序,在我的工作中,我需要一个步骤来获得双重数字的整数部分.所以我选择ceil()或floor()来实现这一点.但输出是不可预测的,远非预期.
整个计划如下:
/*
************************************************************************
Includes
************************************************************************
*/
#include <stdio.h>
#include <stdlib.h>
#include <gsl/gsl_rng.h>
#include <time.h>
#include <math.h>
/* Solvent Particle Propersities*/
typedef struct
{
double vx,vy,rx,ry ; /* velocity AND position */
double cell; /* index of grid */
}solvent_p;
/* Cell Propersities*/
typedef struct
{
double vcm_x,vcm_y ; /* center of mass velocity */
int number; /* number of solvent in the cell */
double roation_angle; /* roation_angle of the cell */
}cell_p;
/* periodic boundary condition judging and …
Run Code Online (Sandbox Code Playgroud) 我使用的是Python 3.4.3.该math.floor
功能为我提供了正面和负面数字的不同答案.例如:
>>> math.floor (19.8)
19
>>> math.floor (-19.8)
-20
Run Code Online (Sandbox Code Playgroud)
为什么我在答案中得到了这个差异?