0

Let's, for example, say that I write down a simple code to manipulate the sin function in a typical language, say python for example. But we know that doesn't always turn out to be as accurate as the built-in sin function that we use in python. What's the equivalent code that python has used to build the sin function?

  • I think it relies on the floating point processor to calculate the sin... – Willem Van Onsem Feb 13 '17 at 13:33
  • 4
    This should answer your question. http://stackoverflow.com/questions/5476189/where-can-i-inspect-pythons-math-functions – TayTay Feb 13 '17 at 13:35
  • @WillemVanOnsem I know it may be a bit stupid to ask this but anyhow can I make use of the FPU in my code? –  Feb 13 '17 at 13:40
  • 1
    In theory, you can calculate trig functions (and many others) with as much precision as you want. What you need is Taylor polynomial, knowledge of Pi and the intervals on which the function is monotonous. – ForceBru Feb 13 '17 at 13:40
  • 1
    @dirac16: actually your processor does that for you: it provides you opcodes to control the floating point unit. Python internally uses a C library if I recall correctly who translates it to the correct op codes. – Willem Van Onsem Feb 13 '17 at 13:41
  • If you want high precision sin and other functions, take a look at [`mpmath`](http://mpmath.org). – PM 2Ring Feb 13 '17 at 13:43
  • It depends. `math.sin` is just a wrapper around the `sin` function provided by `libm`, which, depending on your platform, could use hardware instructions or compute the value in software. – chepner Feb 13 '17 at 14:13

0 Answers0