File: setround.c

package info (click to toggle)
ocaml-zarith 1.14-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 620 kB
  • sloc: ansic: 2,998; ml: 2,767; sh: 288; makefile: 81
file content (27 lines) | stat: -rw-r--r-- 538 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/* Auxiliary function to control FP rounding mode.  Assumes ISO C99. */

#include <fenv.h>
#include <caml/mlvalues.h>

#ifndef FE_DOWNWARD
#define FE_DOWNWARD (-1)
#endif
#ifndef FE_TONEAREST
#define FE_TONEAREST (-1)
#endif
#ifndef FE_TOWARDZERO
#define FE_TOWARDZERO (-1)
#endif
#ifndef FE_UPWARD
#define FE_UPWARD (-1)
#endif

static int modes[4] = {
  FE_DOWNWARD, FE_TONEAREST, FE_TOWARDZERO, FE_UPWARD
};

CAMLprim value caml_ztest_setround(value vmode)
{
  int rc = fesetround(modes[Int_val(vmode)]);
  return Val_bool(rc == 0);
}