double-precision

Floating point arithmetic is too reliable

痞子三分冷 提交于 2019-12-04 02:10:47
问题 I understand that floating point arithmetic as performed in modern computer systems is not always consistent with real arithmetic. I am trying to contrive a small C# program to demonstrate this. eg: static void Main(string[] args) { double x = 0, y = 0; x += 20013.8; x += 20012.7; y += 10016.4; y += 30010.1; Console.WriteLine("Result: "+ x + " " + y + " " + (x==y)); Console.Write("Press any key to continue . . . "); Console.ReadKey(true); } However, in this case, x and y are equal in the end.

Does Fortran have inherent limitations on numerical accuracy compared to other languages?

六月ゝ 毕业季﹏ 提交于 2019-12-03 16:01:09
While working on a simple programming exercise, I produced a while loop (DO loop in Fortran) that was meant to exit when a real variable had reached a precise value. I noticed that due to the precision being used, the equality was never met and the loop became infinite. This is, of course, not unheard of and one is advised that, rather than comparing two numbers for equality, it is best see if the absolute difference between two numbers is less than a set threshold. What I found disappointing was how low I had to set this threshold, even with variables at double precision, for my loop to exit

When using doubles, why isn't (x / (y * z)) the same as (x / y / z)? [duplicate]

冷暖自知 提交于 2019-12-03 06:49:50
问题 This question already has answers here : How to avoid floating point precision errors with floats or doubles in Java? (12 answers) Double calculation producing odd result [duplicate] (3 answers) Closed 4 years ago . This is partly academic, as for my purposes I only need it rounded to two decimal places; but I am keen to know what is going on to produce two slightly different results. This is the test that I wrote to narrow it to the simplest implementation: @Test public void shouldEqual() {

When using doubles, why isn't (x / (y * z)) the same as (x / y / z)? [duplicate]

北战南征 提交于 2019-12-02 21:24:06
This question already has an answer here: How to avoid floating point precision errors with floats or doubles in Java? 12 answers Double calculation producing odd result [duplicate] 3 answers This is partly academic, as for my purposes I only need it rounded to two decimal places; but I am keen to know what is going on to produce two slightly different results. This is the test that I wrote to narrow it to the simplest implementation: @Test public void shouldEqual() { double expected = 450.00d / (7d * 60); // 1.0714285714285714 double actual = 450.00d / 7d / 60; // 1.0714285714285716

How to obtain Fortran precision in MatLAB

不打扰是莪最后的温柔 提交于 2019-12-02 20:57:58
问题 I have a piece of code written in Fortran and in Matlab. They do exactly the same calculation, namely Construct a tanh -field and find its Laplacian Multiply some terms together The result of this multiplication yields a matrix, whose (4,4)th and (6,6)th I subtract. In Fortran their difference is ~1e-20 In Matlab their difference is identically zero. This issue is very critical, as I test if this number is less than zero. Question : Is there a way to perform the calculations such that I get

How to use Bitxor for Double Numbers?

拟墨画扇 提交于 2019-12-02 13:06:05
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? 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 function that would simply remove the "comma" from the Double number by multiplying your starting value by

How to obtain Fortran precision in MatLAB

白昼怎懂夜的黑 提交于 2019-12-02 09:03:33
I have a piece of code written in Fortran and in Matlab. They do exactly the same calculation, namely Construct a tanh -field and find its Laplacian Multiply some terms together The result of this multiplication yields a matrix, whose (4,4)th and (6,6)th I subtract. In Fortran their difference is ~1e-20 In Matlab their difference is identically zero. This issue is very critical, as I test if this number is less than zero. Question : Is there a way to perform the calculations such that I get the same precision in Matlab as in Fortran? I list the codes below: MatLAB clear all weights = [4./9, 1.

Strange multiplication result

北战南征 提交于 2019-12-02 08:59:54
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.51852e-08 xu: 0.786857, 0.561981, 0.255018 yu: 0.534605, -0.82715, 0.173264 F1: -6.2007e-07, -4.61782e-16,

Data type mismatch in fortran

孤街浪徒 提交于 2019-12-02 08:57:07
I've written a rudimentary algorithm in Fortran 95 to calculate the gradient of a function (an example of which is prescribed in the code) using central differences augmented with a procedure known as Richardson extrapolation. function f(n,x) ! The scalar multivariable function to be differentiated integer :: n real(kind = kind(1d0)) :: x(n), f f = x(1)**5.d0 + cos(x(2)) + log(x(3)) - sqrt(x(4)) end function f !=====! !=====! !=====! program gradient !==============================================================================! ! Calculates the gradient of the scalar function f at x=0using a

postfix 'd+0' in Fortran real literal expressions

独自空忆成欢 提交于 2019-12-02 03:19:37
问题 Does anyone knwow what the postfix " d+0 " means in the assignments to M1, M2 and M4 below or is there any resource on the web or a book where one is very likely to find this information? subroutine plot( t, x, p, q, nga, nt, wron, & ngq, gq, ngaq1, ngaq2, gaq, rwh, iwh ) implicit none integer*4 nga, nt, ngq, ngaq1, ngaq2, iwh(*) real*8 t, x(*), p(*), q(*), wron(nga,*), & gq(ngq,*), gaq(ngaq1,ngaq2,*), rwh(*) real*8 M1, M2, M3, M4, mr, mst, h3, Tc integer*8 iflag c DISCRETIZE1( Tc, rwh, iwh )