C++ Builder 串口控件 | C++ Builder 编程技巧 | C++ Builder 操作指南 | C++ Builder 参考手册 | 基础知识 | cfloat 浮点数 | cmath 数学函数 | • acos, acosf, acosl | • acosh, acoshf, acoshl | • asin, asinf, asinl | • asinh, asinhf, asinhl | • atan, atanf, atanl | • atan2, atan2f, atan2l | • atanh, atanhf, atanhl | • ceil, ceilf, ceill | • copysign, copysignf, copysignl | • cos, cosf, cosl | • cosh, coshf, coshl | • exp, expf, expl | • exp2, exp2f, exp2l | • expm1, expm1f, expm1l | • fabs, fabsf, fabsl | • floor, floorf, floorl | • fmod, fmodf, fmodl | • frexp, frexpf, frexpl | • hypot, hypotf, hypotl | • ldexp, ldexpf, ldexpl | • log, logf, logl | • log10, log10f, log10l | • log1p, log1pf, log1pl | • log2, log2f, log2l | • modf, modff, modfl | • nan, nanf, nanl | • poly, polyl | • pow, powf, powl | • pow10, pow10l | • round, roundf, roundl | • sin, sinf, sinl | • sinh, sinhf, sinhl | • sqrt, sqrtf, sqrtl | • tan, tanf, tanl | • tanh, tanhf, tanhl | • trunc, truncf, truncl | • _exception, _exceptionl | • _matherr, _matherrl | • HUGE_VAL, HUGE_VALF, HUGE_VALL, _LHUGE_VAL | • EDOM, ERANGE | • _mexcep, DOMAIN, SING, OVERFLOW, UNDERFLOW, TLOSS, PLOSS, STACKFAULT | • M_E, M_LOG2E, M_LOG10E, M_LN2, M_LN10 | • M_PI, M_PI_2, M_PI_4, M_1_PI, M_2_PI, M_1_SQRTPI, M_2_SQRTPI | • M_SQRT2, M_SQRT_2 | • DOMAIN error 定义域错误 | cstdlib 标准库函数 | System 字符串 | System 日期和时间 | System.Math.hpp 数学函数 | 其他数据类型 | VCL 基础类 | VCL 应用程序 | Pictures 图片 | Graphics 绘图 | Additional 控件 | System 控件 | A ~ Z 字母顺序排列的目录 | 网友留言/技术支持 |
|
floor, floorf, floorl - 向下取整,求不大于 x 的最大整数 |
函数原型:
函数原型 |
C90 |
C99 |
C++98 |
C++11 |
double floor(double x); |
√ |
√ |
√ |
√ |
float floorf(float x); |
|
√ |
|
|
long double floorl(long double x); |
|
√ |
|
|
float floor(float x); |
|
|
√ |
√ |
long double floor(long double x); |
|
|
√ |
√ |
头文件:
#include <cmath>
命名空间:
std
参数:
x:浮点数
返回值:
取整之后的浮点数,是一个小于等于 x 的值,从坐标轴上看,返回值是与 x 重合或在 x 的左侧与 x 距离最近的整数。
例子:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
const wchar_t fmt[] = L"%6.2f %6.2f %6.2f %6.2f %6.2f %6.2llf\r\n";
UnicodeString s = L" value trunc floor ceil round RoundTo\r\n";
s.cat_sprintf(fmt, 5.4 , trunc( 5.4 ), floor( 5.4 ), ceil( 5.4 ), round( 5.4 ), RoundTo( 5.4 ,0));
s.cat_sprintf(fmt, 5.5 , trunc( 5.5 ), floor( 5.5 ), ceil( 5.5 ), round( 5.5 ), RoundTo( 5.5 ,0));
s.cat_sprintf(fmt, 6.5 , trunc( 6.5 ), floor( 6.5 ), ceil( 6.5 ), round( 6.5 ), RoundTo( 6.5 ,0));
s.cat_sprintf(fmt, 6.51, trunc( 6.51), floor( 6.51), ceil( 6.51), round( 6.51), RoundTo( 6.51,0));
s.cat_sprintf(fmt, 6.8 , trunc( 6.8 ), floor( 6.8 ), ceil( 6.8 ), round( 6.8 ), RoundTo( 6.8 ,0));
s.cat_sprintf(fmt, -5.4 , trunc(-5.4 ), floor(-5.4 ), ceil(-5.4 ), round(-5.4 ), RoundTo(-5.4 ,0));
s.cat_sprintf(fmt, -5.5 , trunc(-5.5 ), floor(-5.5 ), ceil(-5.5 ), round(-5.5 ), RoundTo(-5.5 ,0));
s.cat_sprintf(fmt, -6.5 , trunc(-6.5 ), floor(-6.5 ), ceil(-6.5 ), round(-6.5 ), RoundTo(-6.5 ,0));
s.cat_sprintf(fmt, -6.51, trunc(-6.51), floor(-6.51), ceil(-6.51), round(-6.51), RoundTo(-6.51,0));
s.cat_sprintf(fmt, -6.8 , trunc(-6.8 ), floor(-6.8 ), ceil(-6.8 ), round(-6.8 ), RoundTo(-6.8 ,0));
Memo1->Lines->Text = s;
} |
兼容性:
函数 \ C++ Builder 编译器 |
bcc32 |
clang32 |
clang64 |
floor |
√ |
√ |
√ |
floorf |
|
|
√ |
floorl |
√ |
√ |
√ |
相关链接:
• ceil • trunc • round • RoundTo • _matherr • 浮点数异常处理
|
|
|
|