Created
April 19, 2017 02:21
-
-
Save tyabu12/fabdf392e69a2e9d805a08128ffeeccd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <math.h> | |
#include <fenv.h> | |
#include <assert.h> | |
#include <caml/mlvalues.h> | |
#include <caml/alloc.h> | |
static void change_round_mode(int mode) { | |
switch (mode) { | |
case NearestTiesToEven: | |
fesetround(FE_TONEAREST); | |
break; | |
case ToZero: | |
fesetround(FE_TOWARDZERO); | |
break; | |
case Up: | |
fesetround(FE_UPWARD); | |
break; | |
case Down: | |
fesetround(FE_DOWNWARD); | |
break; | |
default: assert(0); break; | |
} | |
} | |
CAMLprim value addc(value mode, value x, value y) { | |
volatile double r, x1 = Double_val(x), y1 = Double_val(y); | |
change_round_mode(Int_val(mode)); | |
r = x1 + y1; | |
change_round_mode(NearestTiesToEven); | |
return caml_copy_double(r); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment