floating-accuracy

How does floating point error propagate when doing mathematical operations in C++?

馋奶兔 提交于 2019-12-01 02:05:58
问题 Let's say that we have declared the following variables float a = 1.2291; float b = 3.99; float variables have precision 6, which (if I understand correctly) means that the difference between the number that the computer actually stores and the actual number that you want will be less than 10^-6 that means that both a and b have some error that is less than 10^-6 so inside the computer a could actually be 1.229100000012123 and b could be 3.9900000191919 now let's say that you have the

floating point number imprecision while iterating

萝らか妹 提交于 2019-11-30 23:55:12
I have a function that computes a point in 3d spaced based on a value in range [0, 1] . The problem I'm facing is, that a binary floating-point number cannot represent exactly 1. The mathematical expression that is evaluated in the function is able to compute a value for t=1.0 , but the value will never be accepted by the function because it checks if for the range before computing. curves_error curves_bezier(curves_PointList* list, curves_Point* dest, curves_float t) { /* ... */ if (t < 0 || t > 1) return curves_invalid_args; /* ... */ return curves_no_error; } How can I, with this function,

Addition error with ruby-1.9.2 [duplicate]

别说谁变了你拦得住时间么 提交于 2019-11-30 20:16:21
This question already has an answer here: ruby: converting from float to integer in ruby produces strange results 3 answers When I add 0.1+0.2 I am getting 0.30000000000000004 but when I add the same number in ruby 1.8.7 I am getting the correct answer 0.3 . I get 0.3 by rounding but I just want to get 0.3 on ruby 1.9.2 by adding 0.1 and 0.2 You need bigdecimal for this to make work. (BigDecimal('0.1') + BigDecimal("0.2")).to_f See below link: http://redmine.ruby-lang.org/issues/4394 Your old ruby lied to you: $ ruby -v ruby 1.8.7 (2010-06-23 patchlevel 299) [x86_64-linux] $ irb irb(main):001

Can I use pandas.dataframe.isin() with a numeric tolerance parameter?

℡╲_俬逩灬. 提交于 2019-11-30 19:43:31
I reviewed the following posts beforehand. Is there a way to use DataFrame.isin() with an approximation factor or a tolerance value? Or is there another method that could? Filter dataframe rows if value in column is in a set list of values use a list of values to select rows from a pandas dataframe EX) df = DataFrame({'A' : [5,6,3.3,4], 'B' : [1,2,3.2, 5]}) In : df Out: A B 0 5 1 1 6 2 2 3.3 3.2 3 4 5 df[df['A'].isin([3, 6], tol=.5)] In : df Out: A B 1 6 2 2 3.3 3.2 You can do a similar thing with numpy's isclose : df[np.isclose(df['A'].values[:, None], [3, 6], atol=.5).any(axis=1)] Out: A B 1

How do you find a float's nearest non-equal value? [duplicate]

我只是一个虾纸丫 提交于 2019-11-30 14:40:28
问题 This question already has answers here : How to alter a float by its smallest increment (or close to it)? (7 answers) Closed 5 years ago . A float (a.k.a. single) value is a 4-byte value, and supposed to represent any real-valued number. Because of the way it is formatted and the finite number of bytes it is made off, there is a minimum value and a maximum value it can represent, and it has a finite precision, depending on it's own value. I would like to know if there is a way to get the

How to Java String.format with a variable precision?

白昼怎懂夜的黑 提交于 2019-11-30 14:33:32
问题 I'd like to vary the precision of a double representation in a string I'm formatting based on user input. Right now I'm trying something like: String foo = String.format("%.*f\n", precision, my_double); however I receive a java.util.UnknownFormatConversionException . My inspiration for this approach was C printf and this resource (section 1.3.1). Do I have a simple syntax error somewhere, does Java support this case, or is there a better approach? Edit: I suppose I could do something like:

PHP/MySQL: Best money operations/storing practices?

我只是一个虾纸丫 提交于 2019-11-30 12:40:04
问题 So, I am planning to make an application (PHP/MySQL) which deals a lot with money, and I am thinking about how to store and operate with the money, referring to PHP float data type and MySQL decimal. I was thinking of two options. One of them is to operate and store money in integer cents format ($dollars * 100) in order not to deal with float inprecisions and to store it in the DB as integer too. The other one is to store in DB as decimal and to use BC Math in PHP for calculations. So I

How do you find a float's nearest non-equal value? [duplicate]

有些话、适合烂在心里 提交于 2019-11-30 11:21:46
This question already has an answer here: How to alter a float by its smallest increment (or close to it)? 7 answers A float (a.k.a. single) value is a 4-byte value, and supposed to represent any real-valued number. Because of the way it is formatted and the finite number of bytes it is made off, there is a minimum value and a maximum value it can represent, and it has a finite precision, depending on it's own value. I would like to know if there is a way to get the closest possible value above or below some reference value, given the finite precision of a float. With integers, this is trivial

What exactly is the “resolution” parameter of numpy float

对着背影说爱祢 提交于 2019-11-30 09:54:06
I am seeking some more understanding about the "resolution" parameter of a numpy float (I guess any computer defined float for that matter). Consider the following script: import numpy as np a = np.finfo(10.1) print a I get an output which among other things prints out: precision=15 resolution= 1.0000000000000001e-15 max= 1.797(...)e+308 min= -max The numpy documentation specifies: "resolution: (floating point number of the appropriate type) The approximate decimal resolution of this type, i.e., 10**-precision." source resolution is derived from precision, but unfortunately this definition is

Why do I need 17 significant digits (and not 16) to represent a double?

对着背影说爱祢 提交于 2019-11-30 06:46:55
Can someone give me an example of a floating point number (double precision), that needs more than 16 significant decimal digits to represent it? I have found in this thread that sometimes you need up to 17 digits, but I am not able to find an example of such a number (16 seems enough to me). Can somebody clarify this? Thanks a lot! My other answer was dead wrong. #include <stdio.h> int main(int argc, char *argv[]) { unsigned long long n = 1ULL << 53; unsigned long long a = 2*(n-1); unsigned long long b = 2*(n-2); printf("%llu\n%llu\n%d\n", a, b, (double)a == (double)b); return 0; } Compile