问题
In C and C++, the modf
function can break floating number into fractional and integral parts.
I'm curious about what does "modf" stand for. What is it shorthand for?
回答1:
what is
modf()
shorthand for?
The function breaks a floating point number up into whole number and fractional parts.
Looking at the 1989 definition (I do not find it in K & R 1st Ed.)...
The
modf
function break the argumentvalue
into integral and fractional parts, each of which has the same sign as the argument. It stores the integral part as adouble
in the object pointed to byiptr
. Themodf
function returns the signed fractional part ofvalue
. C89 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. Could not call it fmod()
as that is used for a %
like function for double
, nor plain mod()
which is too integer like.
Sorry this in only based on my understanding since the late '80s. Perhaps an 1960s/70s reference or guru can be found.
I suspect "mod" as the fractional remainder comes from Fortran of the 1970s, yet my reference books are chest deep in the maze.
回答2:
From the Linux man pages:
Name modf, modff, modfl - extract signed integral and fractional values from floating-point number
Meaning that modf
stands for modulus and fraction, as also @chux - Reinstate Monica suggested.
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. This is for C
, where modf()
works on double
s, modff()
on float
s and modfl()
on long double
s.
来源:https://stackoverflow.com/questions/58986957/what-is-modf-a-math-function-from-c-c-etc-shorthand-for