double-precision

How to use Bitxor for Double Numbers?

末鹿安然 提交于 2019-12-20 07:44:34
问题 I want to use xor for my double numbers in matlab,but bitxor is only working for int numbers. Is there a function that could convert double to int in Matlab? 回答1: The functions You are looking for might be: int8(number) , int16(number) , uint32(number) Any of them will convert Double to an Integer, but You must pick the best one for the result You want to achieve. Remember that You cannot cast from Double to Integer without rounding the number. If I understood You correcly, You could create a

Strange multiplication result

六月ゝ 毕业季﹏ 提交于 2019-12-20 06:15:18
问题 In my code I have this multiplications in a C++ code with all variable types as double[] f1[0] = (f1_rot[0] * xu[0]) + (f1_rot[1] * yu[0]); f1[1] = (f1_rot[0] * xu[1]) + (f1_rot[1] * yu[1]); f1[2] = (f1_rot[0] * xu[2]) + (f1_rot[1] * yu[2]); f2[0] = (f2_rot[0] * xu[0]) + (f2_rot[1] * yu[0]); f2[1] = (f2_rot[0] * xu[1]) + (f2_rot[1] * yu[1]); f2[2] = (f2_rot[0] * xu[2]) + (f2_rot[1] * yu[2]); corresponding to these values Force Rot1 : -5.39155e-07, -3.66312e-07 Force Rot2 : 4.04383e-07, -1

C# High double precision

流过昼夜 提交于 2019-12-19 19:40:01
问题 I'm writing a function that calculates the value of PI, and returns it as a double. So far so good. But once the function gets to 14 digits after the decimal place, it can't hold any more. I'm assuming this is because of the double's limited precision. What should I do to continue getting more numbers after the decimal place? 回答1: I wouldn't do it in floating point at all. Recall that your algorithm is: (1 + 1 / (2 * 1 + 1)) * (1 + 2 / (2 * 2 + 1)) * (1 + 3 / (2 * 3 + 1)) * (1 + 4 / (2 * 4 +

How to compare double numbers?

蹲街弑〆低调 提交于 2019-12-18 09:34:08
问题 I know that when I would like to check if double == double I should write: bool AreSame(double a, double b) { return fabs(a - b) < EPSILON; } But what when I would like to check if a > b or b > a ? 回答1: There is no general solution for comparing floating-point numbers that contain errors from previous operations. The code that must be used is application-specific. So, to get a proper answer, you must describe your situation more specifically. For example, if you are sorting numbers in a list

Function return type mismatch

£可爱£侵袭症+ 提交于 2019-12-18 07:09:04
问题 I'm attempting to recode an old C++ program in Fortran to make use of LAPACK (I'm aware that C++ does have LAPACK++, but I'm having a lot of trouble installing it, so I gave up). I originally didn't have any problems with compilation, but that was when I had all variables declared as REAL . When I started coding the section of the program that required LAPACK, I found that all parameters passed to DSYEV need to be DOUBLE PRECISION . So I tried to change everything to double precision

new BigDecimal(double) vs new BigDecimal(String) [duplicate]

对着背影说爱祢 提交于 2019-12-17 16:48:06
问题 This question already has answers here : BigDecimal from Double incorrect value? (3 answers) Convert double to BigDecimal and set BigDecimal Precision (8 answers) Closed 4 years ago . When BigDecimal is used with an input of double and BigDecimal with an input of String different results seem to appear. BigDecimal a = new BigDecimal(0.333333333); BigDecimal b = new BigDecimal(0.666666666); BigDecimal c = new BigDecimal("0.333333333"); BigDecimal d = new BigDecimal("0.666666666"); BigDecimal x

Should I use double or float?

亡梦爱人 提交于 2019-12-17 02:41:12
问题 What are the advantages and disadvantages of using one instead of the other in C++? 回答1: If you want to know the true answer, you should read What Every Computer Scientist Should Know About Floating-Point Arithmetic. In short, although double allows for higher precision in its representation, for certain calculations it would produce larger errors . The "right" choice is: use as much precision as you need but not more and choose the right algorithm . Many compilers do extended floating point

Decimal Precision Lost after 15th Digit - Bad PI

ε祈祈猫儿з 提交于 2019-12-14 03:35:00
问题 Attempting to print more than 15 decimal digits of PI result in incorrect decimals printing after the 15th decimal. This despite the 30 correct decimal values being assigned and despite using long double to hold the value. The following test case clearly shows the error. This was unexpected. If there would be any error in the digits, I would not expect to see any error until the 25th digit after exhausting the IEEE-754 significand. What rule is in play here that might explain by I can't print

How accurate/precise is java.lang.Math.pow(x, n) for large n?

家住魔仙堡 提交于 2019-12-14 02:18:25
问题 I would like to calculate (1.0-p)^n where p is a double between 0 and 1 (often very close to 0) and n is a positive integer that might be on the order of hundreds or thousands (perhaps larger; I'm not sure yet). If possible I would love to just use Java's built in java.lang.Math.pow(1.0-p, n) for this, but I'm slightly concerned that there might be a gigantic loss of accuracy/precision in doing so with the range of values that I'm interested in. Does anybody have a rough idea of what kind of

CUFFT with double precision

a 夏天 提交于 2019-12-13 16:34:05
问题 I am experiencing some problems with CUDAs FFT library. I declared the inputs as cuDoubleComplex, but the compiler returns the error that this type is incompatible with parameters of type cufftComplex. After some search through the Internet, I found the file cufft.h, in which there is the line typedef cuComplex cufftComplex; . My problem is that in the library cuComplex.h it is clear that cuComplex has a single floating point precision ( typedef cuFloatComplex cuComplex; ), but I would like a