Questions tagged [inexact-arithmetic]

16 questions
36
votes
4 answers

Comparing floats in a pandas column

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 >=…
7
votes
1 answer

Generate "fuzzy" difference of two files in Python, with approximate comparison of floats

I have an issue for comparing two files. Basically, what I want to do is a UNIX-like diff between two files, for example: $ diff -u left-file right-file However my two files contain floats; and because these files were generated on distinct…
7
votes
1 answer

How to convert any number to a clojure.lang.Ratio type in Clojure?

In Scheme I can do: #;> (numerator 1/3) 1 #;> (denominator 1/3) 3 In Clojure I can do something similar: user=> (numerator 1/3) 1 user=> (denominator 1/3) 3 But in Scheme I can do: #;> (numerator 0.3) 3.0 and it is not possible in Clojure: user=>…
Felipe
  • 16,649
  • 11
  • 68
  • 92
4
votes
1 answer

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

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…
3
votes
4 answers

Is the double 0.0 always represented exactly in portable C?

Can the following code be expected to work in all environments that have an ANSI-compliant C compiler? double n = 0; assert(n == 0); What about C++?
kirakun
  • 2,770
  • 1
  • 25
  • 41
2
votes
2 answers

Scheme - "inexact" concept in R5RS numerical tower

While thinking about the way to implement Scheme R5RS, I have become puzzled about the following extract of R5RS (pages 22-23): (remainder -13 -4) ==> -1 (remainder -13 -4.0) ==> -1.0 ; inexact (lcm 32 -36) ==> 288 (lcm 32.0 -36) ==> 288.0 ;…
Nicolas_75
  • 95
  • 6
2
votes
1 answer

Why is (max (sin (/ 5 3)) (sqr 12)) in Scheme/Dr. Racket (Beginning Student Language) evaluated as inexact?

I was reading How to Design Programs and in the Exercise 2.1.1, I am to: Find out whether DrScheme has operations for squaring a number; for computing the sine of an angle; and for determining the maximum of two numbers. -- sec. 2.2, ex 2.1.1 My…
1
vote
2 answers

DBL_MAX loses significant part of its precision after being re-parsed from string

I'm running this code on my iPhone: double d = DBL_MAX; NSString *s = [NSString stringWithFormat:@"%.0f", d]; double dp = atof([s cStringUsingEncoding:[NSString defaultCStringEncoding]]); NSString *pe = d == dp ? @"YES" : @"NO"; double one =…
Sergey Mikhanov
  • 8,880
  • 9
  • 44
  • 54
1
vote
2 answers

Dividing a float by 10

Possible Duplicate: Why can't decimal numbers be represented exactly in binary? I am developing a pretty simple algorithm for mathematics use under C++. And I have a floating point variable named "step", each time I finish a while loop, I need…
Shane Hsu
  • 7,937
  • 6
  • 39
  • 63
1
vote
2 answers

How does the Scheme function inexact->exact operate?

How does the Scheme procedure inexact->exact, described in SICP, operate?
ismail naeem
  • 11
  • 1
  • 2
1
vote
1 answer

exact/inexact results like sqrt and integer roots

R6RS 3.4 Implementation requirements reads ... Potentially inexact operations such as sqrt, when applied to exact arguments, should produce exact answers whenever possible (for example the square root of an exact 4 ought to be an exact 2). (1)…
false
  • 10,264
  • 13
  • 101
  • 209
1
vote
1 answer

how can I obtain exact values of sin and cos in matlab for angles like pi/4?

if I write in matlab cos(pi/4) I get this form: 0.7071 when I'd prefer getting it actual value of (2)^(1/2)/2 to write formulas more clearly. is there a way to do what I ask?
user1834153
  • 330
  • 5
  • 20
0
votes
0 answers

CGAL exact predicate inexact constructions

I know that it is possible to get exact comparison results without constructing the objects exactly by using exact_predicate_inexact_constructions kernel in CGAL. The thing that I wonder is upto which degree I can use the inexact objects to get an…
Merve A
  • 31
  • 4
0
votes
2 answers

SQL Server casting result of arithmetic

I'm just looking at some very minor discrepancies in a report I'm putting together and I'm confused as to what is the best practice in SQL server for casting and if somebody can me point in the right direction to explain what I'm seeing. A very…
MrEdmundo
  • 5,105
  • 13
  • 46
  • 58
0
votes
0 answers

What is the typical user-defined logic which is executed after FE_INEXACT is raised?

I more or less understand / imagine the typical user-defined logic which is executed: after FE_OVERFLOW or FE_UNDERFLOW is raised: not critical case: try to recover by, for example, adjusting some values / coefficients and redo the…
pmor
  • 5,392
  • 4
  • 17
  • 36
1
2