inexact-arithmetic

Comparing floats in a pandas column

邮差的信 提交于 2019-12-29 05:03:29
问题 I have the following dataframe: actual_credit min_required_credit 0 0.3 0.4 1 0.5 0.2 2 0.4 0.4 3 0.2 0.3 I need to add a column indicating where actual_credit >= min_required_credit. The result would be: actual_credit min_required_credit result 0 0.3 0.4 False 1 0.5 0.2 True 2 0.4 0.4 True 3 0.1 0.3 False I am doing the following: df['result'] = abs(df['actual_credit']) >= abs(df['min_required_credit']) However the 3rd row (0.4 and 0.4) is constantly resulting in False. After researching

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

℡╲_俬逩灬. 提交于 2019-12-17 10:06:23
问题 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 <-

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 <-