Skip to content

Instantly share code, notes, and snippets.

@tyabu12
Created April 19, 2017 02:21
Show Gist options
  • Save tyabu12/fabdf392e69a2e9d805a08128ffeeccd to your computer and use it in GitHub Desktop.
Save tyabu12/fabdf392e69a2e9d805a08128ffeeccd to your computer and use it in GitHub Desktop.
#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