From 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 7 Apr 2024 13:41:34 -0500 Subject: new repository --- devdocs/c/numeric%2Fmath%2Fmodf.html | 78 ++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 devdocs/c/numeric%2Fmath%2Fmodf.html (limited to 'devdocs/c/numeric%2Fmath%2Fmodf.html') diff --git a/devdocs/c/numeric%2Fmath%2Fmodf.html b/devdocs/c/numeric%2Fmath%2Fmodf.html new file mode 100644 index 00000000..7ee360cd --- /dev/null +++ b/devdocs/c/numeric%2Fmath%2Fmodf.html @@ -0,0 +1,78 @@ +

modf, modff, modfl

Defined in header <math.h>
float       modff( float arg, float* iptr );
+
(1) (since C99)
double      modf( double arg, double* iptr );
+
(2)
long double modfl( long double arg, long double* iptr );
+
(3) (since C99)
+1-3) Decomposes given floating point value arg into integral and fractional parts, each having the same type and sign as arg. The integral part (in floating-point format) is stored in the object pointed to by iptr.

Parameters

+ + +
arg - floating point value
iptr - pointer to floating point value to store the integral part to

Return value

If no errors occur, returns the fractional part of x with the same sign as x. The integral part is put into the value pointed to by iptr.

+

The sum of the returned value and the value stored in *iptr gives arg (allowing for rounding).

+

Error handling

This function is not subject to any errors specified in math_errhandling.

+

If the implementation supports IEEE floating-point arithmetic (IEC 60559),

+

Notes

This function behaves as if implemented as follows:

+
double modf(double value, double *iptr)
+{
+#pragma STDC FENV_ACCESS ON
+    int save_round = fegetround();
+    fesetround(FE_TOWARDZERO);
+    *iptr = std::nearbyint(value);
+    fesetround(save_round);
+    return copysign(isinf(value) ? 0.0 : value - (*iptr), value);
+}

Example

#include <stdio.h>
+#include <math.h>
+#include <float.h>
+ 
+int main(void)
+{
+    double f = 123.45;
+    printf("Given the number %.2f or %a in hex,\n", f, f);
+ 
+    double f3;
+    double f2 = modf(f, &f3);
+    printf("modf() makes %.2f + %.2f\n", f3, f2);
+ 
+    int i;
+    f2 = frexp(f, &i);
+    printf("frexp() makes %f * 2^%d\n", f2, i);
+ 
+    i = ilogb(f);
+    printf("logb()/ilogb() make %f * %d^%d\n", f/scalbn(1.0, i), FLT_RADIX, i);
+ 
+    // special values
+    f2 = modf(-0.0, &f3);
+    printf("modf(-0) makes %.2f + %.2f\n", f3, f2);
+    f2 = modf(-INFINITY, &f3);
+    printf("modf(-Inf) makes %.2f + %.2f\n", f3, f2);
+}

Possible output:

+
Given the number 123.45 or 0x1.edccccccccccdp+6 in hex,
+modf() makes 123.00 + 0.45
+frexp() makes 0.964453 * 2^7
+logb()/ilogb() make 1.92891 * 2^6
+modf(-0) makes -0.00 + -0.00
+modf(-Inf) makes -INF + -0.00

References

See also

+ +
+
(C99)(C99)(C99)
rounds to nearest integer not greater in magnitude than the given value
(function)
C++ documentation for modf
+

+ © cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
+ https://en.cppreference.com/w/c/numeric/math/modf +

+
-- cgit v1.2.3