- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
modf()
family of functions都带一个指针参数:
float modff( float arg, float* iptr );
double modf( double arg, double* iptr );
long double modfl( long double arg, long double* iptr );
用于返回其输入arg
的整数部分(小数部分为实际返回值)。
如果我只需要小数部分,我可以通过传递NULL
来“跳过”整数部分的计算吗?
无论是我喜欢的 cppreference 页面,还是 man modff
,都没有说明当您为 iptr
传递 NULL
时会发生什么,而一些其他标准库函数将 NULL 作为“忽略此参数”的指示。
最佳答案
standard没有定义这个
Description
2 The modf functions break the argument value into integral and fractional parts, each of which has the same type and sign as the argument. They store the integral part (in floating-point format) in the object pointed to by iptr.
Returns
3 The modf functions return the signed fractional part of value.
因此传递 NULL
时的行为将是未定义的。您可能会发现一些允许它的编译器,但任何依赖它的代码都不可移植(即使在同一编译器的不同版本之间)。
关于我可以将 NULL 传递给 modf/modff 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65578459/
我正在尝试存储十进制数的所有数字。我决定使用 modf 来实现此目的。我的代码段是; struct high_precision scan_high(int *j) { int i,a;
无法让 modf() 工作。 在注释后包含了 Xcode 编译器错误消息。 #import #include #include int main (int argc, const char *
获取 python (python 3) Decimal 的整数部分和小数部分的最有效方法是什么? 这是我现在拥有的: from decimal import * >>> divmod(Decimal
希望你一切顺利。 我正在尝试使用 ASCII 代码转换单词的索引(数字)。例如: index 0 -> " " index 94 -> "~" index 625798 -> "e@A" ind
如果小数部分的前 3 位数字包含“9”,则应显示此代码,但不起作用。令人惊讶的是,“mod”变量对于任何数字都是 0。 int main( void ) { float number, dmo
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是偏离主题的,
我实现了两个不同的函数来将双位数舍入为整数。 这是第一个函数 static inline int round_v1(double value) { int t; __asm {
我正在尝试创建一个函数,借助 modf() 将一个值拆分为两个单独的值。我希望能够将米转换为英尺和英寸,我知道我应该怎么做,但我似乎无法让它与函数一起工作。 #include #include v
在我分析的应用程序中,我发现在某些情况下,此函数能够占用总执行时间的 10% 以上。 正在使用 MSVC++ 2008 编译器,以供引用...我不记得 modf 是否映射到单个指令,或者是否有可能使它
我想获得浮点数的整数和小数部分。这很容易使用 std::modf但该函数不是 constexpr。这是什么原因,有什么替代方法? 最佳答案 Is there a constexpr alternati
我明白它的作用,但我想知道该函数在内部做了什么来分离 float 。我可以想到一个非常 hacky 的方法来使用整数转换来完成它,但我真的希望它是一个比这更优雅的解决方案......它直接访问位并转换
我有这个静态方法,它接收一个 double 并“剪切”它的小数尾部,在点后留下两位数字。 几乎一直工作。我注意到当它接收到 2.3,然后将其变为 2.29。 0.3、1.3、3.3、4.3 和 102
我最近遇到了一个问题,我在 MSVC 中遇到了段错误,而在 GCC 中却不会。 几小时后我意识到我的 MSVC 版本显然不支持以下语法: double value = 3.4; double frac
modf() family of functions都带一个指针参数: float modff( float arg, float* iptr ); double modf( d
来自 http://docs.python.org/2/library/math.html : math.frexp(x) Return the mantissa and exponent of x
我正在开发一个没有数学库的平台,所以我需要构建自己的工具。我目前获取分数的方法是将 float 转换为定点(乘以 (float)0xFFFF,强制转换为 int),仅获取下部(掩码为 0xFFFF)并
为什么 modf 的 intpart 输出强制为 double ?除非输入的整数部分本身是 double 值,否则根据定义,输出不是始终是整数。 int main () { double p,
好像没有? 最佳答案 使用 PHP 的 fmod . 关于php - 如何在 php 中使用 C modf 函数?,我们在Stack Overflow上找到一个类似的问题: https://stack
我只是想通过取计数器相对于列表长度的模数,使用递增计数器循环遍历 (10) 个名称的列表。但是,代码似乎在这里和那里跳过了一个数字。我尝试了 modf() 和 modff() 以及不同类型的转换,但没
在 C 和 C++ 中,modf 函数可以将 float 分成小数部分和整数部分。 我很好奇“modf”代表什么。它的简写是什么? 最佳答案 来自Linux man pages : Name modf
我是一名优秀的程序员,十分优秀!