1

I have a Linux command line utility that is a binary. It could be something simple like: echo $((23.5/7.33))

I want a Python program that sets various rounding modes on my Intel CPU then calls my command line utility with those FPU settings to check for numerical instability.

What is the syntax to do this, or is it even possible? Assume my command line utility is nice and isn't setting FPU flags within it's code.

Chad Brewbaker
  • 2,523
  • 2
  • 19
  • 26
  • Fortran binaries can set FPU settings any time. – Vladimir F Героям слава Jul 25 '14 at 19:08
  • Yeah, so can C. Assuming that the binary is not setting the FPU rounding word I would still like to know the syntax to do this. It wouldn't be hard to intercept the assembler and remove FPU mode resets if the binary was naughty. – Chad Brewbaker Jul 25 '14 at 19:13
  • 2
    See http://stackoverflow.com/a/21637817/270986 for one way to mess with the FPU settings, via ctypes. – Mark Dickinson Jul 25 '14 at 19:35
  • import evil , haha. I'll try that hopefully Linux isn't too far off from OSX. – Chad Brewbaker Jul 25 '14 at 20:02
  • I think the ctypes stuff @MarkDickinson points out is the way to go - [this blog post](http://rafaelbarreto.wordpress.com/2009/03/30/controlling-fpu-rounding-modes-with-python/) focusses particularly on the rounding modes. See also [this question/answer](http://stackoverflow.com/questions/16000574/tie-breaking-of-round-with-numpy) – Jonathan Dursi Jul 25 '14 at 20:20

0 Answers0