[英]what is “modf()” (a math function from C/C++ etc.) shorthand for?
In C and C++, the modf
function can break floating number into fractional and integral parts.在 C 和 C++ 中,
modf
function 可以将浮点数分解为小数和整数部分。
I'm curious about what does "modf" stand for.我很好奇“modf”代表什么。 What is it shorthand for?
它是什么的简写?
From the Linux man pages :从Linux 手册页:
Name modf, modff, modfl - extract signed integral and fractional values from floating-point number
名称 modf、modff、modfl - 从浮点数中提取有符号整数和小数
Meaning that modf
stands for mod ulus and f raction, as also @chux - Reinstate Monica suggested.这意味着
modf
代表模数和分数,正如@chux - Reinstate Monica 所建议的那样。
We can also read in the same page,我们也可以在同一页阅读,
Synopsis
概要
#include <math.h>
double modf(double x, double *iptr);
float modff(float x, float, *iptr);
long double modfl(long double x, long double *iptr);
This makes clear that the f does not stand for float
, but for fraction.这清楚地表明 f 不代表
float
,而是代表分数。 This is for C
, where modf()
works on double
s, modff()
on float
s and modfl()
on long double
s.这是针对
C
的,其中modf()
适用于double
s, modff()
适用于float
s, modfl()
于long double
s。
what is
modf()
shorthand for?modf()
的简写是什么?
The function breaks a floating point number up into whole number and fractional parts. function 将浮点数分解为整数和小数部分。
Looking at the 1989 definition (I do not find it in K & R 1st Ed.)...查看 1989 年的定义(我在 K & R 第一版中找不到它。)...
The
modf
function break the argumentvalue
into integral and fractional parts, each of which has the same sign as the argument.modf
function 将参数value
分解为整数和小数部分,每个部分与参数的符号相同。 It stores the integral part as adouble
in the object pointed to byiptr
.它将整数部分作为
double
精度部分存储在iptr
指向的 object 中。 Themodf
function returns the signed fractional part ofvalue
.modf
function 返回value
的有符号小数部分。 C89 7.5.4.6C89 7.5.4.6
... has lead me to think of "mod" as the "left over" part which cannot be expressed with an integer and "f" as fraction to describe the returning value. ...使我将“mod”视为“剩余”部分,不能用 integer 和“f”作为描述返回值的分数来表示。 Could not call it
fmod()
as that is used for a %
like function for double
, nor plain mod()
which is too integer like.不能将其称为
fmod()
,因为它用于像double
之类的%
,也不能称为普通mod()
,后者太像 integer 。
Sorry this in only based on my understanding since the late '80s.抱歉,仅基于我自 80 年代后期以来的理解。 Perhaps an 1960s/70s reference or guru can be found.
也许可以找到 1960 年代/70 年代的参考资料或大师。
I suspect "mod" as the fractional remainder comes from Fortran of the 1970s, yet my reference books are chest deep in the maze .我怀疑“mod”作为小数余数来自 1970 年代的 Fortran,但我的参考书在迷宫深处。
After doing some research I stumbled upon the Mod and remainder are not the same that states that mod and remainder are different things, when both numbers have the same sign, mod and remainder are the same, but when one of the signs is different the programming language implementation can have different results as shown on this table .在做了一些研究之后,我偶然发现Mod 和余数不相同,说明 mod 和余数是不同的东西,当两个数字具有相同的符号时,mod 和余数是相同的,但是当其中一个符号不同时,编程语言实现可以有不同的结果,如下表所示。 In
C
fmod( A, B )
returns the remainder
of A and B
, the difference with the %
operator is that it works on floating point numbers, meaning that A and B or any
is a floating point number ( double
, float
or long double
).在
C
fmod( A, B )
返回A and B
的remainder
,与%
运算符的区别在于它适用于浮点数,这意味着A and B or any
是浮点数( double
、 float
或long double
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.