Skip to content

Instantly share code, notes, and snippets.

@comex
Last active August 13, 2023 22:12
Show Gist options
  • Save comex/061c2f7316e5bfbded0fed50bf15b424 to your computer and use it in GitHub Desktop.
Save comex/061c2f7316e5bfbded0fed50bf15b424 to your computer and use it in GitHub Desktop.
#pragma STDC FENV_ACCESS ON
#include <signal.h>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <fenv.h>
static void check(const char *where) {
printf("%-40s: fegetround() => %#x\n", where, fegetround());
}
static void handler(int _) {
check("in signal handler before fesetround");
assert(!fesetround(FE_DOWNWARD));
check("in signal handler after fesetround");
}
int main() {
int round = FE_UPWARD;
printf("fesetround(%#x)\n", round);
assert(!fesetround(round));
check("before signal handler");
assert(SIG_ERR != signal(SIGINT, handler));
assert(!raise(SIGINT));
check("after signal handler");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment