Re: where is math_sin defined?
> On 10 Feb 2019, at 16:43, Chris Angelico wrote: > > On Mon, Feb 11, 2019 at 3:37 AM Barry Scott wrote: >> >> On Sunday, 10 February 2019 15:15:32 GMT Jon Ribbens wrote: >>> As an aside, how is 'math.sin' actually implemented? mathmodule.c >>> refers to the function 'math_sin' but that name is not defined >>> anywhere in the Python source code. I'm a bit mystified as to how >>> CPython manages to compile! >> >> I used gdb to find it: >> > > Effective, if a little tedious. Tedious? Its fast and accurate only took 20s and got the answer right first time. I had spent a few minutes reading and greping the code and my grep fu found to many false positives. Barry > > My technique was to first confirm that there was nothing saying > "math_sin" anywhere in the repo (trust but verify - doesn't hurt to do > a quick "git grep"), then to search mathmodule.c for "sin(", since > searching for "sin" on its own gave way too many hits. That led me to > the definition of sinpi(), then to asin() and sin(), both being > defined using the FUNC1 template. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: where is math_sin defined?
On Mon, Feb 11, 2019 at 3:37 AM Barry Scott wrote: > > On Sunday, 10 February 2019 15:15:32 GMT Jon Ribbens wrote: > > As an aside, how is 'math.sin' actually implemented? mathmodule.c > > refers to the function 'math_sin' but that name is not defined > > anywhere in the Python source code. I'm a bit mystified as to how > > CPython manages to compile! > > I used gdb to find it: > Effective, if a little tedious. My technique was to first confirm that there was nothing saying "math_sin" anywhere in the repo (trust but verify - doesn't hurt to do a quick "git grep"), then to search mathmodule.c for "sin(", since searching for "sin" on its own gave way too many hits. That led me to the definition of sinpi(), then to asin() and sin(), both being defined using the FUNC1 template. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: where is math_sin defined?
On Sunday, 10 February 2019 15:15:32 GMT Jon Ribbens wrote: > As an aside, how is 'math.sin' actually implemented? mathmodule.c > refers to the function 'math_sin' but that name is not defined > anywhere in the Python source code. I'm a bit mystified as to how > CPython manages to compile! I used gdb to find it: Breakpoint 1, math_sin (self=, args=0) at / usr/src/debug/python3-3.7.2-4.fc29.x86_64/Modules/mathmodule.c:1176 1176FUNC1(sin, sin, 0, (gdb) l 1171 "remainder($module, x, y, /)\n--\n\n" 1172 "Difference between x and the closest integer multiple of y. \n\n" 1173 "Return x - n*y where n*y is the closest integer multiple of y. \n" 1174 "In the case where x is exactly halfway between two multiples of\n" 1175 "y, the nearest even value of n is used. The result is always exact.") 1176FUNC1(sin, sin, 0, 1177 "sin($module, x, /)\n--\n\n" 1178 "Return the sine of x (measured in radians).") 1179FUNC1(sinh, sinh, 1, 1180 "sinh($module, x, /)\n--\n\n" (gdb) Barry -- https://mail.python.org/mailman/listinfo/python-list