On Thu, Oct 14, 2010 at 12:07 PM, cej38 <junkerme...@gmail.com> wrote:

> I am kinda sorry that I started this whole thing.  I don't need
> another lesson in limits.  The simple fact of the matter is that, in
> my code, I run into a place where I have a comparison (= some-value
> (some-function some-data)), the function, data, and value can change.
> In a use case that I am interested in, I run into the problem stated,
>
> user=> (= 0.0001 (- 12.305 12.3049))
> false
>
> I am OK with replacing the = function with something like float=
> discussed above, but whatever I change it two needs to work.  If
> anyone has found a way, that reliably works, please post it here.
> Further, <, >, <=, and >= would also be appreciated.  Thank you.
>
>
>
Comparing two floats for equality is almost always wrong.  What you want to
do is check whether their difference is less than some small number.  To
compare two floating point numbers x and y, you want to do (<= (Math/abs (-
x y)) epsilon), where epsilon is some suitably small number (based on the
size of the error of the computation).

Brian


>
>
>
>
> On Oct 13, 6:56 pm, David Sletten <da...@bosatsu.net> wrote:
> > Here's a slightly more informal argument. Suppose you challenge me that 1
> is not equal to 0.9999... What you are saying is that 1 - 0.9999... is not
> equal to 0, i.e., the difference is more than 0. But for any positive value
> arbitrarily close to 0 I can show that 0.999... is closer to 1 than that. If
> you were to say that the difference is 0.1, I could show that 0.999... > 0.9
> so the difference is smaller. For every 0 you added to your challenge: 0.1,
> 0.01, 0.001 I could provide a counterexample with another 9: 0.9, 0.99,
> 0.999, ... In other words, there is no positive number that satisfies your
> claim, so equality must hold.
> >
> > Have all good days,
> > David Sletten
> >
> > On Oct 13, 2010, at 6:36 PM, Matt Fowles wrote:
> >
> >
> >
> > > Felix~
> >
> > > You are correct that the sequence of numbers
> >
> > > 0.9
> > > 0.99
> > > 0.999
> > > ...
> >
> > > asymptotically approaches 1; however, the number 0.9999... (with an
> infinite number of 9s) is equal to 1.  The formal proof of this is fairly
> tricky as the definition of the real number is usually done as an
> equivalence class of Cauchy sequences; a simplified version of the proof can
> be thought of as follows:
> >
> > > For any two real numbers a and b there exists an infinite number of
> real numbers c such that a < c < b.  However, there do not exist any numbers
> between 0.99999... and 1, thus they must be same number.
> >
> > > As it turns out, it took mathematicians a long time to nail down
> formally exactly what we naively think of as "numbers".
> >
> > > Matt
> >
> > > On Wed, Oct 13, 2010 at 6:27 PM, Felix H. Dahlke <f...@ubercode.de>
> wrote:
> > > On 13/10/10 22:28, David Sletten wrote:
> >
> > > > On Oct 12, 2010, at 5:44 PM, Brian Hurt wrote:
> >
> > > >>   For example, in base 10, 1/3 * 3 = 0.99999...
> >
> > > > It may seem counterintuitive, but that statement is perfectly true.
> > > > 1 = 0.9999...
> >
> > > > That's a good test of how well you understand infinity.
> >
> > > I'm clearly not a mathematician, but doesn't 0.99999... asymptotically
> > > approach 1, i.e. never reaching it? How is that the same as 1?
> >
> > > --
> > > You received this message because you are subscribed to the Google
> > > Groups "Clojure" group.
> > > To post to this group, send email to clojure@googlegroups.com
> > > Note that posts from new members are moderated - please be patient with
> your first post.
> > > To unsubscribe from this group, send email to
> > > clojure+unsubscr...@googlegroups.com<clojure%2bunsubscr...@googlegroups.com>
> > > For more options, visit this group at
> > >http://groups.google.com/group/clojure?hl=en
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com<clojure%2bunsubscr...@googlegroups.com>
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to