what is “modf()” (a math function from C/C++ etc.) shorthand for?

偶尔善良 提交于 2021-02-18 18:54:42

问题


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 argument value into integral and fractional parts, each of which has the same sign as the argument. It stores the integral part as a double in the object pointed to by iptr. The modf function returns the signed fractional part of value. 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 doubles, modff() on floats and modfl() on long doubles.



来源:https://stackoverflow.com/questions/58986957/what-is-modf-a-math-function-from-c-c-etc-shorthand-for

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!