floating-accuracy

VB.NET running sum in nested loop inside Parallel.for Synclock loses information

夙愿已清 提交于 2019-12-11 19:13:55
问题 Below is the best representation I have been able to develop for calculating a running sum inside a loop that's nested inside a Parallel.for loop in VB.NET (Visual Studio 2010, .NET Framework 4). Note that when showing the results in `sum' to the screen, there is a slight difference between the two sums, and hence loss of information in the parallelized variant. So how is the information being lost, and what's happening? Can anyone offer some "microsurgery" on methodology for keeping a

Keeping accuracy when taking decimal to power of integer

陌路散爱 提交于 2019-12-11 19:11:11
问题 My code is as follows (I have simplified it for ease of reading, sorry for the lack of functions): #include <stdio.h> #include <string.h> #include <math.h> #include <iostream> #include <iomanip> #include <fstream> #include <time.h> #include <stdlib.h> #include <sstream> #include <gmpxx.h> using namespace std; #define PI 3.14159265358979323846 int main() { int a,b,c,d,f,i,j,k,m,n,s,t,Success,Fails; double p,theta,phi,Time,Averagetime,Energy,energy,Distance,Length,DotProdForce, Forcemagnitude

Why are these numbers not equal?

蓝咒 提交于 2019-12-11 17:55:44
问题 The following code is obviously wrong. What's the problem? i <- 0.1 i <- i + 0.05 i ## [1] 0.15 if(i==0.15) cat("i equals 0.15") else cat("i does not equal 0.15") ## i does not equal 0.15 回答1: General (language agnostic) reason Since not all numbers can be represented exactly in IEEE floating point arithmetic (the standard that almost all computers use to represent decimal numbers and do math with them), you will not always get what you expected. This is especially true because some values

Why `0.4/2` equals to `0.2` meanwhile `0.6/3` equals to `0.19999999999999998` in python? [duplicate]

烂漫一生 提交于 2019-12-11 16:52:42
问题 This question already has answers here : Is floating point math broken? (31 answers) Closed 4 years ago . I know these are float point division. But why did these two formula behave differently? And I did some more investigation, the result confusing me even more: >>>0.9/3 0.3 >>>1.2/3 0.39999999999999997 >>>1.5/3 0.5 What's the logic here to decide whether the result is printed with one decimal place or more? PS: I used python3.4 to do the experiment above. 回答1: Because the exact values of

Fixed Point to Floating Point and Backwards

柔情痞子 提交于 2019-12-11 14:46:02
问题 Is converting Fixed Pt. (fixed n bit for fraction) to IEEE double safe ? ie: does IEEE double format can represent all numbers a fixed point can represent ? The test: a number goes to floating pt format then back to it's original fixed pt format. 回答1: Assuming your fixed point numbers are stored as 32-bit integers, yes, IEEE double precision can represent any value representable in fixed point. This is because double has a 53-bit mantissa, your fixed point values only have 32 bits of

Why do certain floating point calculations turn the way they do? (e.g. 123456789f +1 = 123456792)

本小妞迷上赌 提交于 2019-12-11 14:28:31
问题 I'm trying to get a better understanding of floating point arithmetic, the attending errors that occur and accrue, as well as why exactly the results turn out the way they do. Here are 3 Examples in particular I'm currently working on: 1.) 0.1+0.1 +0.1 +0.1 +0.1 +0.1 +0.1 +0.1 +0.1 +0.1 -1.0 = -1.1102230246251565E-16 aka adding 0.1 10 times gives me a number slightly less than 1.0 . However, 0.1 is represented (as a double) as slightly larger than 0.1 . Also *0.1*3* is slightly larger than 0

Floating Point Modulo Problem

时光毁灭记忆、已成空白 提交于 2019-12-11 13:29:29
问题 I've stumbled onto a very strange bug. Read the comments in the code to see what the bug is exactly, but essentially a variable modulo 1 is returning 1 (but it doesn't equal 1!). I'm assuming there is a display problem where the float is extremely close to one but not exactly. However, it should be moduloing to zero. I can't test for this case easily because (last % 1) != 1.0 ! When I try plugging the same numbers into another python terminal, everything behaves correctly. What's going on?

Causing underflow in ieee-754 floating point format using subtraction

风格不统一 提交于 2019-12-11 09:48:00
问题 This seems basic but I am having a lot of trouble answering the following question: Give two numbers X and Y represented in the IEEE754 format such that computing X-Y will result in underflow. To my understanding every operation can potentially result in underflow but for the life of mine I cant find an example for subtraction. PLEASE HELP!!! thanks 回答1: When default exception handling is in effect, a subtraction that produces a tiny (in the subnormal interval 1 ) non-zero result conceptually

MATLAB float accuracy

时光毁灭记忆、已成空白 提交于 2019-12-11 07:09:07
问题 I want to check numerical stability of QR algorithm, for this i need to create matrix like this: S = diag(2.^(-1:-1:-80)); But it has rank 46, i think it is because of lack of accuracy. But in the book i'm reading it is full ranked matrix. How can i increase accuracy of computations? 回答1: You can use vpa (variable precision ariuthmetic): >> S = diag(2.^vpa((-1:-1:-80)), 100); %// 100 here is number of precision digits >> rank(S) ans = 80 Note that the result is of type sym . Convert to double

python function to set accuracy of float

≡放荡痞女 提交于 2019-12-11 04:07:23
问题 I would like to make a function: def accuracy(number, index): For example accuracy(2.5e-10, -5) would return 0. accuracy(49, 2) would return 0. accuracy(50, 2) would return 100. So basically it would round to the closest 10 power of the index index How would you do that? 回答1: def accuracy(n, i): return round(float(n) / 10**i) * 10**i 来源: https://stackoverflow.com/questions/18219400/python-function-to-set-accuracy-of-float