elementary-functions

how to loop over the elementary arithmetic symbols

孤人 提交于 2019-12-24 06:11:19
问题 I want to check if 7 digits can get to 100 when putting elementary arithmetic symbols between them. def is_hundred(n1,n2,n3,n4,n5,n6,n7): p = [+,-,*,/] for p1 in p: for p2 in p: for p3 in p: for p4 in p: for p5 in p: for p6 in p: if n1 p1 n2 p2 n3 p3 n4 p4 n5 p5 n6 p6 n7 == 100: return "success" how can i replace the variables with the arithmetic symbols that are in the list? 回答1: In case you didn't hear it: using eval is evil. So that's definitely not code that I'd put in production. That

Why does table-based sin approximation literature always use this formula when another formula seems to make more sense?

我与影子孤独终老i 提交于 2019-12-17 20:44:34
问题 The literature on computing the elementary function sin with tables refers to the formula: sin(x) = sin(Cn) * cos(h) + cos(Cn) * sin(h) where x = Cn + h , Cn is a constant for which sin(Cn) and cos(Cn) have been pre-computed and are available in a table, and, if following Gal's method, Cn has been chosen so that both sin(Cn) and cos(Cn) are closely approximated by floating-point numbers. The quantity h is close to 0.0 . An example of reference to this formula is this article (page 7). I don't

How to compute correctly rounded trigonometric functions in degrees?

北慕城南 提交于 2019-11-30 13:58:26
How could I define trigonometric functions that take arguments in degrees instead of the usual radians, and compute correctly rounded results for these arguments? Multiplying the argument by M_PI/180.0 before passing it to the corresponding function in radians does not work, because M_PI/180.0 is not π/180. Section 5.5 of the Handbook of Floating-Point Arithmetic offers a method to compute the correctly rounded product of the argument by π/180, but some arguments will still be such that this product is close to the midpoint between two consecutive representable floats, and then applying even a

How to compute correctly rounded trigonometric functions in degrees?

ぐ巨炮叔叔 提交于 2019-11-29 19:36:46
问题 How could I define trigonometric functions that take arguments in degrees instead of the usual radians, and compute correctly rounded results for these arguments? Multiplying the argument by M_PI/180.0 before passing it to the corresponding function in radians does not work, because M_PI/180.0 is not π/180. Section 5.5 of the Handbook of Floating-Point Arithmetic offers a method to compute the correctly rounded product of the argument by π/180, but some arguments will still be such that this