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%2Ffenv%2Fferound.html | 88 +++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 devdocs/c/numeric%2Ffenv%2Fferound.html (limited to 'devdocs/c/numeric%2Ffenv%2Fferound.html') diff --git a/devdocs/c/numeric%2Ffenv%2Fferound.html b/devdocs/c/numeric%2Ffenv%2Fferound.html new file mode 100644 index 00000000..7bbe06b4 --- /dev/null +++ b/devdocs/c/numeric%2Ffenv%2Fferound.html @@ -0,0 +1,88 @@ +

fegetround, fesetround

Defined in header <fenv.h>
int fesetround( int round );
+
(1) (since C99)
int fegetround();
+
(2) (since C99)

1) Attempts to establish the floating-point rounding direction equal to the argument round, which is expected to be one of the floating-point rounding macros.

+

2) Returns the value of the floating-point rounding macro that corresponds to the current rounding direction.

+

Parameters

+ +
round - rounding direction, one of floating-point rounding macros

Return value

1) ​0​ on success, non-zero otherwise.

+

2) the floating-point rounding macro describing the current rounding direction or a negative value if the direction cannot be determined.

+

Notes

The current rounding mode, reflecting the effects of the most recent fesetround, can also be queried with FLT_ROUNDS.

+

Example

#include <fenv.h>
+#include <math.h>
+#include <stdio.h>
+ 
+// #pragma STDC FENV_ACCESS ON
+ 
+void show_fe_current_rounding_direction(void)
+{
+    printf("current rounding direction:  ");
+    switch (fegetround()) {
+           case FE_TONEAREST:  printf ("FE_TONEAREST");  break;
+           case FE_DOWNWARD:   printf ("FE_DOWNWARD");   break;
+           case FE_UPWARD:     printf ("FE_UPWARD");     break;
+           case FE_TOWARDZERO: printf ("FE_TOWARDZERO"); break;
+           default:            printf ("unknown");
+    };
+    printf("\n");
+}
+ 
+int main(void)
+{
+    /* Default rounding direction */
+    show_fe_current_rounding_direction();
+    printf("+11.5 -> %+4.1f\n", rint(+11.5)); /* midway between two integers */
+    printf("+12.5 -> %+4.1f\n", rint(+12.5)); /* midway between two integers */
+ 
+    /* Save current rounding direction. */
+    int curr_direction = fegetround();
+ 
+    /* Temporarily change current rounding direction. */
+    fesetround(FE_DOWNWARD);
+    show_fe_current_rounding_direction();
+    printf("+11.5 -> %+4.1f\n", rint(+11.5));
+    printf("+12.5 -> %+4.1f\n", rint(+12.5));
+ 
+    /* Restore default rounding direction. */
+    fesetround(curr_direction);
+    show_fe_current_rounding_direction();
+ 
+    return 0;
+}

Possible output:

+
current rounding direction:  FE_TONEAREST
++11.5 -> +12.0
++12.5 -> +12.0
+current rounding direction:  FE_DOWNWARD
++11.5 -> +11.0
++12.5 -> +12.0
+current rounding direction:  FE_TONEAREST

References

See also

+ + +
+
(C99)(C99)(C99)
rounds to an integer using current rounding mode
(function)
+
(C99)(C99)(C99)(C99)(C99)(C99)(C99)(C99)(C99)
rounds to an integer using current rounding mode with
exception if the result differs
(function)
C++ documentation for fegetround, fesetround
+

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

+
-- cgit v1.2.3