floating-accuracy

mean from pandas and numpy differ

ぃ、小莉子 提交于 2019-11-30 06:40:52
问题 I have a MEMS IMU on which I've been collecting data and I'm using pandas to get some statistical data from it. There are 6 32-bit floats collected each cycle. Data rates are fixed for a given collection run. The data rates vary between 100Hz and 1000Hz and the collection times run as long as 72 hours. The data is saved in a flat binary file. I read the data this way: import numpy as np import pandas as pd dataType=np.dtype([('a','<f4'),('b','<f4'),('c','<f4'),('d','<f4'),('e','<f4'),('e','

Why 0.1 + 0.2 == 0.3 in D?

假装没事ソ 提交于 2019-11-30 05:50:26
问题 assert(0.1 + 0.2 != 0.3); // shall be true is my favorite check that a language uses native floating point arithmetic. C++ #include <cstdio> int main() { printf("%d\n", (0.1 + 0.2 != 0.3)); return 0; } Output: 1 http://ideone.com/ErBMd Python print(0.1 + 0.2 != 0.3) Output: True http://ideone.com/TuKsd Other examples Java: http://ideone.com/EPO6X C#: http://ideone.com/s14tV Why is this not true for D? As understand D uses native floating point numbers. Is this a bug? Do they use some specific

Detecting precision loss when converting from double to float

安稳与你 提交于 2019-11-30 04:07:45
问题 I am writing a piece of code in which i have to convert from double to float values. I am using boost::numeric_cast to do this conversion which will alert me of any overflow/underflow. However i am also interested in knowing if that conversion resulted in some precision loss or not. For example double source = 1988.1012; float dest = numeric_cast<float>(source); Produces dest which has value 1988.1 Is there any way available in which i can detect this kind of precision loss/rounding 回答1: You

PHP/MySQL: Best money operations/storing practices?

人走茶凉 提交于 2019-11-30 03:45:51
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 googled all the night to find out which is the best option to use and didn't find a clear answer. The only

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

天大地大妈咪最大 提交于 2019-11-30 03:41:03
问题 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 回答1: You can do a similar

C's pow() function as per header file <math.h> not working properly

霸气de小男生 提交于 2019-11-29 18:19:10
I see that for the following code produces the result as below, any idea on why is the output like this? #include <stdio.h> #include <math.h> int main() { int i = 0; for(i = 0; i < 10; i++) { printf("%d\t\t\t%d\t\t\t", i, (int)pow(10, i)); printf("%f\n", pow(10, i)); } return 0; } Outputs: 0 1 1.000000 1 10 10.000000 2 99 100.000000 3 1000 1000.000000 4 9999 10000.000000 5 100000 100000.000000 6 1000000 1000000.000000 7 9999999 10000000.000000 8 99999999 100000000.000000 9 999999999 1000000000.000000 Use the round() function before casting to int , else the trailing digits will just get

Finding the closest floating point value less than a specific integer value in C++?

佐手、 提交于 2019-11-29 17:18:38
I have an input floating point value that is 0.0f <= value < 1.0f (note less than one). When multiplying this value up to a larger range, naturally the floating point precision is decreased meaning the value can end up outside of the equivalent range. For example if I start off with a value such as: 0.99999983534521f Then multiply it by 100, I get: 100.000000000000f Which is fine, but how do I then reduce the floating point representation to be the nearest floating point value that is still less than 100? I found this little manual trick: union test { int integer; float floating; }; test value

Floating point less-than-equal comparisons after addition and substraction

倾然丶 夕夏残阳落幕 提交于 2019-11-29 16:53:32
Is there a "best practice" for less-than-equal comparisons with floating point number after a series of floating-point arithmetic operations? I have the following example in R (although the question applies to any language using floating-point). I have a double x = 1 on which I apply a series of additions and subtractions. In the end x should be exactly one but is not due to floating-point arithmetic (from what I gather). Here is the example: > stop_times <- seq(0.25, 2, by = .25) > expr <- expression(replicate(100,{ x <- 1 for(i in 1:10) { tmp <- rexp(1, 1) n <- sample.int(1e2, 1) delta <-

MySQL “greater than” condition sometimes returns row with equal value

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-29 13:52:55
I'm running into a baffling issue with a basic MySQL query. This is my table: id | rating 1 | 1317.17 2 | 1280.59 3 | 995.12 4 | 973.88 Now, I'm attempting to find all rows where the rating column is larger than a certain value. If I try the following query: SELECT * FROM (`users`) WHERE `rating` > '995.12' It correctly returns 2 . But, if I try SELECT * FROM (`users`) WHERE `rating` > '973.88' it returns 4 ! So it's as if it thinks the 973.88 in the table is greater than 973.88, but it doesn't make the same mistake with 995.12. This happens regardless of whether I run the query from a PHP

Accuracy of floating point arithmetic

旧巷老猫 提交于 2019-11-29 13:30:54
I'm having trouble understanding the output of this program int main() { double x = 1.8939201459282359e-308; double y = 4.9406564584124654e-324; printf("%23.16e\n", 1.6*y); printf("%23.16e\n", 1.7*y); printf("%23.16e\n", 1.8*y); printf("%23.16e\n", 1.9*y); printf("%23.16e\n", 2.0*y); printf("%23.16e\n", x + 1.6*y); printf("%23.16e\n", x + 1.7*y); printf("%23.16e\n", x + 1.8*y); printf("%23.16e\n", x + 1.9*y); printf("%23.16e\n", x + 2.0*y); } The output is 9.8813129168249309e-324 9.8813129168249309e-324 9.8813129168249309e-324 9.8813129168249309e-324 9.8813129168249309e-324 1.8939201459282364e