Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #21795 > unrolled thread

Quasi 0

Started byDavid RF <davranfor@gmail.com>
First post2012-06-04 02:32 -0700
Last post2012-06-04 04:59 -0700
Articles 20 — 9 participants

Back to article view | Back to comp.lang.c


Contents

  Quasi 0 David RF <davranfor@gmail.com> - 2012-06-04 02:32 -0700
    Re: Quasi 0 Noob <root@127.0.0.1> - 2012-06-04 11:56 +0200
      Re: Quasi 0 David RF <davranfor@gmail.com> - 2012-06-04 03:05 -0700
        Re: Quasi 0 James Kuyper <jameskuyper@verizon.net> - 2012-06-04 07:10 -0400
          Re: Quasi 0 David RF <davranfor@gmail.com> - 2012-06-04 04:48 -0700
            Re: Quasi 0 David RF <davranfor@gmail.com> - 2012-06-04 04:56 -0700
            Re: Quasi 0 "BartC" <bc@freeuk.com> - 2012-06-04 13:05 +0100
              Re: Quasi 0 Keith Thompson <kst-u@mib.org> - 2012-06-04 14:55 -0700
            Re: Quasi 0 James Kuyper <jameskuyper@verizon.net> - 2012-06-04 08:05 -0400
          Re: Quasi 0 nick_keighley_nospam@hotmail.com - 2012-06-05 03:54 -0700
            Re: Quasi 0 James Kuyper <jameskuyper@verizon.net> - 2012-06-05 08:07 -0400
            Re: Quasi 0 jgk@panix.com (Joe keane) - 2012-06-05 13:32 +0000
    Re: Quasi 0 Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-06-04 06:51 -0400
      Re: Quasi 0 David RF <davranfor@gmail.com> - 2012-06-04 03:56 -0700
        Re: Quasi 0 "BartC" <bc@freeuk.com> - 2012-06-04 12:08 +0100
          Re: Quasi 0 David RF <davranfor@gmail.com> - 2012-06-04 04:14 -0700
        Re: Quasi 0 James Dow Allen <jdallen2000@yahoo.com> - 2012-06-04 04:25 -0700
      Re: Quasi 0 "BartC" <bc@freeuk.com> - 2012-06-04 12:53 +0100
    Re: Quasi 0 James Kuyper <jameskuyper@verizon.net> - 2012-06-04 07:55 -0400
      Re: Quasi 0 David RF <davranfor@gmail.com> - 2012-06-04 04:59 -0700

#21795 — Quasi 0

FromDavid RF <davranfor@gmail.com>
Date2012-06-04 02:32 -0700
SubjectQuasi 0
Message-ID<75ac0f7b-5989-46c4-b35e-e3dbdeddf25a@f14g2000yqe.googlegroups.com>
Hi friends:
Machine epsilon is the maximum relative error of the chosen rounding
procedure

#include <stdio.h>
#include <math.h>
#include <float.h>

int main(void)
{
  double a = 0.1;
  double b = 0.1;

  a += 1.0;
  a -= 1.0;

  printf("a == b = %s\n", a == b ? "equals" : "unequals");
  printf("a == b = %s\n", fabs(a - b) < DBL_EPSILON ? "equals" :
"unequals");
  return 0;
}

Is this a good method for test the equality?

[toc] | [next] | [standalone]


#21797

FromNoob <root@127.0.0.1>
Date2012-06-04 11:56 +0200
Message-ID<jqi0nm$d33$1@dont-email.me>
In reply to#21795
David RF wrote:

> Is this a good method for test the equality?

If you're bored on a rainy afternoon, you can read David Goldberg's
looong article on FP arithmetic.

http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html

[toc] | [prev] | [next] | [standalone]


#21798

FromDavid RF <davranfor@gmail.com>
Date2012-06-04 03:05 -0700
Message-ID<02098625-5771-48e0-baf6-20f41066edb8@h10g2000yqn.googlegroups.com>
In reply to#21797
On 4 jun, 11:56, Noob <r...@127.0.0.1> wrote:
> David RF wrote:
> > Is this a good method for test the equality?
>
> If you're bored on a rainy afternoon, you can read David Goldberg's
> looong article on FP arithmetic.
>
> http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html

Can you link to someone else's website where formulas do not mix
letters and numbers? :)

[toc] | [prev] | [next] | [standalone]


#21803

FromJames Kuyper <jameskuyper@verizon.net>
Date2012-06-04 07:10 -0400
Message-ID<jqi531$4kj$1@dont-email.me>
In reply to#21798
On 06/04/2012 06:05 AM, David RF wrote:
> On 4 jun, 11:56, Noob <r...@127.0.0.1> wrote:
>> David RF wrote:
>>> Is this a good method for test the equality?
>>
>> If you're bored on a rainy afternoon, you can read David Goldberg's
>> looong article on FP arithmetic.
>>
>> http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html
> 
> Can you link to someone else's website where formulas do not mix
> letters and numbers? :)

Such formulas are the clearest and most natural way to describe the
concepts being discussed. If your mathematical background is not
sufficiently advanced for you to be able to understand such formulas,
it's also insufficient to understand the corresponding concepts. You
should wait until you've learned some algebra before attempting to read
things like this. If you've already tried to learn algebra, and came
away with an aversion to it, you should consider avoiding technically
oriented career paths such as computer programming.
-- 
James Kuyper

[toc] | [prev] | [next] | [standalone]


#21808

FromDavid RF <davranfor@gmail.com>
Date2012-06-04 04:48 -0700
Message-ID<2a148e85-d20a-4500-bdbc-2bb9a5a134fe@c19g2000yqk.googlegroups.com>
In reply to#21803
On 4 jun, 13:10, James Kuyper <jameskuy...@verizon.net> wrote:
> On 06/04/2012 06:05 AM, David RF wrote:
>
> > On 4 jun, 11:56, Noob <r...@127.0.0.1> wrote:
> >> David RF wrote:
> >>> Is this a good method for test the equality?
>
> >> If you're bored on a rainy afternoon, you can read David Goldberg's
> >> looong article on FP arithmetic.
>
> >>http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html
>
> > Can you link to someone else's website where formulas do not mix
> > letters and numbers? :)
>
> Such formulas are the clearest and most natural way to describe the
> concepts being discussed. If your mathematical background is not
> sufficiently advanced for you to be able to understand such formulas,
> it's also insufficient to understand the corresponding concepts. You
> should wait until you've learned some algebra before attempting to read
> things like this. If you've already tried to learn algebra, and came
> away with an aversion to it, you should consider avoiding technically
> oriented career paths such as computer programming.

I'm asking for the simplest way to detect round errors due to binary
representation
of floating numbers. learn algebra? career? you assume too much

[toc] | [prev] | [next] | [standalone]


#21812

FromDavid RF <davranfor@gmail.com>
Date2012-06-04 04:56 -0700
Message-ID<d73053cc-6022-4b3b-b444-c9336d66d81e@d6g2000vbe.googlegroups.com>
In reply to#21808
On 4 jun, 13:48, David RF <davran...@gmail.com> wrote:
> On 4 jun, 13:10, James Kuyper <jameskuy...@verizon.net> wrote:
>
>
>
> > On 06/04/2012 06:05 AM, David RF wrote:
>
> > > On 4 jun, 11:56, Noob <r...@127.0.0.1> wrote:
> > >> David RF wrote:
> > >>> Is this a good method for test the equality?
>
> > >> If you're bored on a rainy afternoon, you can read David Goldberg's
> > >> looong article on FP arithmetic.
>
> > >>http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html
>
> > > Can you link to someone else's website where formulas do not mix
> > > letters and numbers? :)
>
> > Such formulas are the clearest and most natural way to describe the
> > concepts being discussed. If your mathematical background is not
> > sufficiently advanced for you to be able to understand such formulas,
> > it's also insufficient to understand the corresponding concepts. You
> > should wait until you've learned some algebra before attempting to read
> > things like this. If you've already tried to learn algebra, and came
> > away with an aversion to it, you should consider avoiding technically
> > oriented career paths such as computer programming.
>
> I'm asking for the simplest way to detect round errors due to binary
> representation
> of floating numbers. learn algebra? career? you assume too much

representation of floating point numbers, excuse my poor english

[toc] | [prev] | [next] | [standalone]


#21814

From"BartC" <bc@freeuk.com>
Date2012-06-04 13:05 +0100
Message-ID<jqi8a7$mlg$1@dont-email.me>
In reply to#21808
"David RF" <davranfor@gmail.com> wrote in message 
news:2a148e85-d20a-4500-bdbc-2bb9a5a134fe@c19g2000yqk.googlegroups.com...
> On 4 jun, 13:10, James Kuyper <jameskuy...@verizon.net> wrote:

> I'm asking for the simplest way to detect round errors due to binary
> representation
> of floating numbers. learn algebra? career? you assume too much

The simplest way is to test whether the absolute difference between two 
numbers, is less than some threshold such as 0.0001.

What the best value of that should be, and whether having a fixed limit at 
all would work, depends on your application.

If you want to test whether two results are equal, allowing for minor 
rounding errors, then that's a little different, especially if possible 
results cover a wide range of magnitudes. Here you really want to ignore the 
last few bits of the floating point representation, but it gets tricky to do 
and you need a bit of background.

-- 
Bartc 

[toc] | [prev] | [next] | [standalone]


#21835

FromKeith Thompson <kst-u@mib.org>
Date2012-06-04 14:55 -0700
Message-ID<lnehpueo7k.fsf@nuthaus.mib.org>
In reply to#21814
"BartC" <bc@freeuk.com> writes:
> "David RF" <davranfor@gmail.com> wrote in message 
> news:2a148e85-d20a-4500-bdbc-2bb9a5a134fe@c19g2000yqk.googlegroups.com...
>> On 4 jun, 13:10, James Kuyper <jameskuy...@verizon.net> wrote:
>
>> I'm asking for the simplest way to detect round errors due to binary
>> representation
>> of floating numbers. learn algebra? career? you assume too much
>
> The simplest way is to test whether the absolute difference between two 
> numbers, is less than some threshold such as 0.0001.
>
> What the best value of that should be, and whether having a fixed limit at 
> all would work, depends on your application.
>
> If you want to test whether two results are equal, allowing for minor 
> rounding errors, then that's a little different, especially if possible 
> results cover a wide range of magnitudes. Here you really want to ignore the 
> last few bits of the floating point representation, but it gets tricky to do 
> and you need a bit of background.

Ideally, the nature of the test for near-equality needs to reflect the
nature of the computation(s) that created the error.

A simple test like

    abs(x - y) <= 0.0001

is sensible only in limited circumstances.  Sometimes it makes sense to
test for an absolute difference, sometimes it makes sense to test the
ratio, and sometimes you really need something more complicated.

The question you're trying to answer is whether the discrepancy between
two floating-point values reflects an actual mathematical difference or
a rounding error.  Determining that, even imperfectly, requires an
understanding of what errors the computation(s) *could* have produced.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
    Will write code for food.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

[toc] | [prev] | [next] | [standalone]


#21815

FromJames Kuyper <jameskuyper@verizon.net>
Date2012-06-04 08:05 -0400
Message-ID<jqi8a6$mkt$1@dont-email.me>
In reply to#21808
On 06/04/2012 07:48 AM, David RF wrote:
> On 4 jun, 13:10, James Kuyper <jameskuy...@verizon.net> wrote:
>> On 06/04/2012 06:05 AM, David RF wrote:
...
>>> Can you link to someone else's website where formulas do not mix
>>> letters and numbers? :)
>>
>> Such formulas are the clearest and most natural way to describe the
>> concepts being discussed. If your mathematical background is not
>> sufficiently advanced for you to be able to understand such formulas,
>> it's also insufficient to understand the corresponding concepts. You
>> should wait until you've learned some algebra before attempting to read
>> things like this. If you've already tried to learn algebra, and came
>> away with an aversion to it, you should consider avoiding technically
>> oriented career paths such as computer programming.
> 
> I'm asking for the simplest way to detect round errors due to binary
> representation
> of floating numbers. ... 

While your original question was about dealing with floating point
round-off errors, I responded to that question in a different message.
In this message, I was responding only to your reaction to discovering
the use of algebra in David Goldberg's article.

> ...learn algebra? career? you assume too much

No, I was rather careful to write my message to avoid making those
assumptions; I didn't assume you were planning a technically-oriented
career - I merely advised against pursing one if you found algebra too
difficult. I didn't assume that you'd already tried and failed to learn
algebra, I deliberately worded it to be equally appropriate whether or
not you'd tried to learn algebra yet.

I did assume that you needed to learn algebra to correctly understand
propagation of error. Only the very simplest concepts in that subject
can be explained without it; not enough to be useful, just enough to be
dangerous.
-- 
James Kuyper

[toc] | [prev] | [next] | [standalone]


#21863

Fromnick_keighley_nospam@hotmail.com
Date2012-06-05 03:54 -0700
Message-ID<020694a0-5010-4af2-974f-2dcd587c9d1b@googlegroups.com>
In reply to#21803
On Monday, June 4, 2012 12:10:24 PM UTC+1, James Kuyper wrote:
> On 06/04/2012 06:05 AM, David RF wrote:
> > On 4 jun, 11:56, Noob <r...@127.0.0.1> wrote:
> >> David RF wrote:

> >> If you're bored on a rainy afternoon, you can read David Goldberg's
> >> looong article on FP arithmetic.
> >>
> >> http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html

excellent stuff. I must re-read it.

> > Can you link to someone else's website where formulas do not mix
> > letters and numbers? :)
> 
> Such formulas are the clearest and most natural way to describe the
> concepts being discussed. If your mathematical background is not
> sufficiently advanced for you to be able to understand such formulas,
> it's also insufficient to understand the corresponding concepts. You
> should wait until you've learned some algebra before attempting to read
> things like this. 

doesn't everyone's education include basic algebra?

> If you've already tried to learn algebra, and came
> away with an aversion to it,

I never quite understood this, though I've encounterd it. It's like there's a conceptual hole in their brain so that they can't take the abstraction step to encompass algebra. Actual neural architecture or just bad teaching? 

> you should consider avoiding technically
> oriented career paths such as computer programming.

I'm not sure i'd go that far. you can do quite a lot without algebra. Though floating point arithmatic sounds to be pushing it!  

[toc] | [prev] | [next] | [standalone]


#21865

FromJames Kuyper <jameskuyper@verizon.net>
Date2012-06-05 08:07 -0400
Message-ID<jqksq5$cgv$1@dont-email.me>
In reply to#21863
On 06/05/2012 06:54 AM, nick_keighley_nospam@hotmail.com wrote:
> On Monday, June 4, 2012 12:10:24 PM UTC+1, James Kuyper wrote:
>> On 06/04/2012 06:05 AM, David RF wrote:
>>> On 4 jun, 11:56, Noob <r...@127.0.0.1> wrote:
...
>>>> http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html
...
>>> Can you link to someone else's website where formulas do not mix
>>> letters and numbers? :)
>>
>> Such formulas are the clearest and most natural way to describe the
>> concepts being discussed. If your mathematical background is not
>> sufficiently advanced for you to be able to understand such formulas,
>> it's also insufficient to understand the corresponding concepts. You
>> should wait until you've learned some algebra before attempting to read
>> things like this. 
> 
> doesn't everyone's education include basic algebra?

People as young as six are learning to program nowadays; possibly
younger. The simplest explanation for his desire for "formulas [that] do
not mix letters and numbers" is that he hasn't taken algebra yet. I'm
not assuming he's that young, but I did consider the possibility. The
complexity of the language in his messages is near the upper limit of
what I'd expect such a young person to be capable of, but it's not over
that limit. The second simplest explanation is that he took algebra, but
failed to master it.

>> If you've already tried to learn algebra, and came
>> away with an aversion to it,
> 
> I never quite understood this, though I've encounterd it. It's like there's a conceptual hole in their brain so that they can't take the abstraction step to encompass algebra. Actual neural architecture or just bad teaching? 

I used to tutor math and science for undergrads at community college.
The ones who needed tutoring were often taking math or science classes
to meet a requirement, rather than because they found them interesting.
I ran into all kinds of math phobia. As a math lover, I never fully
understood it, but I did develop some helpful techniques for explaining
things to such people.

>> you should consider avoiding technically
>> oriented career paths such as computer programming.
> 
> I'm not sure i'd go that far. you can do quite a lot without algebra. Though floating point arithmatic sounds to be pushing it!

That why I inserted the weasel words "consider" and "avoid".
-- 
James Kuyper

[toc] | [prev] | [next] | [standalone]


#21869

Fromjgk@panix.com (Joe keane)
Date2012-06-05 13:32 +0000
Message-ID<jql1p5$ctp$1@reader1.panix.com>
In reply to#21863
In article <020694a0-5010-4af2-974f-2dcd587c9d1b@googlegroups.com>,
 <nick_keighley_nospam@hotmail.com> wrote:
>Actual neural architecture or just bad teaching?

the second one!

i used to [very long time ago] tutor kids

the kids are smart, it's the adults who are missing some knifes

i'm like go from basic algebra to understanding calculus in a few weeks

no prob, let's go

[toc] | [prev] | [next] | [standalone]


#21800

FromEric Sosman <esosman@ieee-dot-org.invalid>
Date2012-06-04 06:51 -0400
Message-ID<jqi3ur$u1d$1@dont-email.me>
In reply to#21795
On 6/4/2012 5:32 AM, David RF wrote:
> Hi friends:
> Machine epsilon is the maximum relative error of the chosen rounding
> procedure
>
> #include<stdio.h>
> #include<math.h>
> #include<float.h>
>
> int main(void)
> {
>    double a = 0.1;
>    double b = 0.1;
>
>    a += 1.0;
>    a -= 1.0;
>
>    printf("a == b = %s\n", a == b ? "equals" : "unequals");
>    printf("a == b = %s\n", fabs(a - b)<  DBL_EPSILON ? "equals" :
> "unequals");
>    return 0;
> }
>
> Is this a good method for test the equality?

     No.

     Rounding adds or subtracts an amount that is proportional to
the magnitude of the rounded number.  DBL_EPSILON is scaled for
numbers near +-1, but is of completely the wrong size for numbers
around +-1E30 or +-1E-30.  DBL_EPSILON is about 1E-16 on many
machines, so consider the values 1E-20 and 1E-30: They differ
by much less than the typical DBL_EPSILON, yet one is ten billion
times the other.  Do you want to consider a ten billion-fold
discrepancy "equal?"

-- 
Eric Sosman
esosman@ieee-dot-org.invalid

[toc] | [prev] | [next] | [standalone]


#21801

FromDavid RF <davranfor@gmail.com>
Date2012-06-04 03:56 -0700
Message-ID<bfad6935-b012-44b5-b5ce-bd10814d8aaf@t8g2000yqd.googlegroups.com>
In reply to#21800
On 4 jun, 12:51, Eric Sosman <esos...@ieee-dot-org.invalid> wrote:
> El 04/06/2012 05:32 AM, David RF escribió:
>
>
>
>
>
>
>
> > Hola amigos:
> Epsilon> de la máquina es el máximo error relativo de redondeo elegido
> > Procedimiento de
>
> > # Include
> > # Include <math.h>
> > # Include <float.h>
>
> > Int main (void)
> > {
> > Doble a = 0,1;
> > Doble b = 0,1;
>
> > A + = 1.0;
> > A - = 1,0;
>
> > Printf ("a == b =% s ​​\ n", un "igual" == b: "desiguales"?);
> > Printf ("a == b =% s ​​\ n", fábricas (a - b) <DBL_EPSILON "iguales"?
> > "Desiguales");
> > Return 0;
> >}
>
> > ¿Es este un buen método para la prueba de la igualdad?
>
> No.
>
> Completan suma o resta una cantidad que es proporcional a
> la magnitud del número redondeado. DBL_EPSILON se escala para la
> números de cerca de + -1, pero es por completo de la talla equivocada de los números
> alrededor de + o +-1e30-1E-30. DBL_EPSILON se trata de 1E-16 en muchosmáquinas, a fin de considerar los valores 1E-20 y 1E-30: Se diferencian
> por mucho menos que el DBL_EPSILON típica, sin embargo, uno es diez mil millones
> veces el otro. ¿Quieres tener en cuenta un niño de diez mil millones de veces
> discrepancia "iguales?"

Thanks, I get the point

[toc] | [prev] | [next] | [standalone]


#21802

From"BartC" <bc@freeuk.com>
Date2012-06-04 12:08 +0100
Message-ID<jqi4vk$41r$1@dont-email.me>
In reply to#21801

"David RF" <davranfor@gmail.com> wrote in message 
news:bfad6935-b012-44b5-b5ce-bd10814d8aaf@t8g2000yqd.googlegroups.com...
> On 4 jun, 12:51, Eric Sosman <esos...@ieee-dot-org.invalid> wrote:
>> El 04/06/2012 05:32 AM, David RF escribió:

>> > Hola amigos:
>> Epsilon> de la máquina es el máximo error relativo de redondeo elegido
>> > Procedimiento de
>>
>> > # Include
>> > # Include <math.h>
>> > # Include <float.h>
>>
>> > Int main (void)
>> > {
>> > Doble a = 0,1;
>> > Doble b = 0,1;
>>
>> > A + = 1.0;
>> > A - = 1,0;
>>
>> > Printf ("a == b =% s ​​\ n", un "igual" == b: "desiguales"?);
>> > Printf ("a == b =% s ​​\ n", fábricas (a - b) <DBL_EPSILON "iguales"?
>> > "Desiguales");
>> > Return 0;
>> >}
>>
>> > ¿Es este un buen método para la prueba de la igualdad?
>>
>> No.
>>
>> Completan suma o resta una cantidad que es proporcional a
>> la magnitud del número redondeado. DBL_EPSILON se escala para la
>> números de cerca de + -1, pero es por completo de la talla equivocada de 
>> los números
>> alrededor de + o +-1e30-1E-30. DBL_EPSILON se trata de 1E-16 en 
>> muchosmáquinas, a fin de considerar los valores 1E-20 y 1E-30: Se 
>> diferencian
>> por mucho menos que el DBL_EPSILON típica, sin embargo, uno es diez mil 
>> millones
>> veces el otro. ¿Quieres tener en cuenta un niño de diez mil millones de 
>> veces
>> discrepancia "iguales?"
>
> Thanks, I get the point

What happened there?

-- 
Bartc 

[toc] | [prev] | [next] | [standalone]


#21804

FromDavid RF <davranfor@gmail.com>
Date2012-06-04 04:14 -0700
Message-ID<bf0f60d2-8ac1-41de-9a90-956b3a22b815@f16g2000yqg.googlegroups.com>
In reply to#21802
On 4 jun, 13:08, "BartC" <b...@freeuk.com> wrote:
> "David RF" <davran...@gmail.com> wrote in message
>
> news:bfad6935-b012-44b5-b5ce-bd10814d8aaf@t8g2000yqd.googlegroups.com...
>
>
>
> > On 4 jun, 12:51, Eric Sosman <esos...@ieee-dot-org.invalid> wrote:
> >> El 04/06/2012 05:32 AM, David RF escribió:
> >> > Hola amigos:
> >> Epsilon> de la máquina es el máximo error relativo de redondeo elegido
> >> > Procedimiento de
>
> >> > # Include
> >> > # Include <math.h>
> >> > # Include <float.h>
>
> >> > Int main (void)
> >> > {
> >> > Doble a = 0,1;
> >> > Doble b = 0,1;
>
> >> > A + = 1.0;
> >> > A - = 1,0;
>
> >> > Printf ("a == b =% s ​​\ n", un "igual" == b: "desiguales"?);
> >> > Printf ("a == b =% s ​​\ n", fábricas (a - b) <DBL_EPSILON "iguales"?
> >> > "Desiguales");
> >> > Return 0;
> >> >}
>
> >> > ¿Es este un buen método para la prueba de la igualdad?
>
> >> No.
>
> >> Completan suma o resta una cantidad que es proporcional a
> >> la magnitud del número redondeado. DBL_EPSILON se escala para la
> >> números de cerca de + -1, pero es por completo de la talla equivocada de
> >> los números
> >> alrededor de + o +-1e30-1E-30. DBL_EPSILON se trata de 1E-16 en
> >> muchosmáquinas, a fin de considerar los valores 1E-20 y 1E-30: Se
> >> diferencian
> >> por mucho menos que el DBL_EPSILON típica, sin embargo, uno es diez mil
> >> millones
> >> veces el otro. ¿Quieres tener en cuenta un niño de diez mil millones de
> >> veces
> >> discrepancia "iguales?"
>
> > Thanks, I get the point
>
> What happened there?

Oops, excuse me, I replied to Eric after using the translator

[toc] | [prev] | [next] | [standalone]


#21806

FromJames Dow Allen <jdallen2000@yahoo.com>
Date2012-06-04 04:25 -0700
Message-ID<44806000-6bbf-4035-a737-d1cb9a1d5407@kw17g2000pbb.googlegroups.com>
In reply to#21801
On Jun 4, 5:56 pm, David RF <davran...@gmail.com> wrote:
> On June 4, 12:51, Eric Sosman <those...@ ieee-dot-org.invalid> wrote:
>
>
>
>
>
>
>
> > On 04/06/2012 5:32 a.m., David RF wrote:
>
> >> Hello friends:
> > Epsilon> machine is the maximum relative error of rounding chosen
> Procedure >>
>
> >> # Include# Include <math.h> >>
> # Include <float.h> >>
>
> >> Int main (void)
> {>>
> Turn >> = 0.1;
> Double >> b = 0.1;
>
> >> A + = 1.0;
> >> A - = 1.0;
>
> >> Printf ("a == b =% s ​​\ n", an "equal" == b "unequal"?)
> >> Printf ("a == b =% s ​​\ n", factories (a - b) <DBL_EPSILON "equal"?
> >> "Unequal");
> >> Return 0;
> >>}
>
> >> Is this a good method to test for equality?
>
> > No.
>
> > Rounding adds or subtracts an amount which is proportional to
> > The sheer numbers rounded. DBL_EPSILON is scaled to the
> > Numbers of about + -1, but it is completely the wrong size of the numbers
> > About + or +-1e30-1E-30. DBL_EPSILON is muchosmáquinas 1E-16 in order to consider the values ​​1E-1E-20 and 30: They differ
> > For much less than the typical DBL_EPSILON, however, one is ten billion
> > Times the other. Want to take account of a ten billion times
> > Discrepancy "equal?"
>
> Thanks, I get the point

This is in reply to BartC, who asks "What happened?"

I respond to David's post, first clicking "Translate to English."
The post now has less Spanish than before (though still doesn't
look like Eric's post).

And this was with *Old* Google Groups.
I've not yet dared to learn what wondrous features
*New* Google Groups has!!  ::slaps face with hand::

James

[toc] | [prev] | [next] | [standalone]


#21809

From"BartC" <bc@freeuk.com>
Date2012-06-04 12:53 +0100
Message-ID<jqi7kn$iod$1@dont-email.me>
In reply to#21800
"Eric Sosman" <esosman@ieee-dot-org.invalid> wrote in message 
news:jqi3ur$u1d$1@dont-email.me...
> On 6/4/2012 5:32 AM, David RF wrote:

>> Is this a good method for test the equality?
>
>     No.

>consider the values 1E-20 and 1E-30: They differ
> by much less than the typical DBL_EPSILON, yet one is ten billion
> times the other.  Do you want to consider a ten billion-fold
> discrepancy "equal?"

I remember having a similar conversation with my bank: I was suggesting that 
a 0.1% interest rate was, to all intents and purposes, a zero interest rate; 
they insisted on still calling it an interest-bearing account.

Of course, from their point of view, it was still returning an infinitely 
higher amount of interest than the zero-rated one, even after tax.

-- 
Bartc 

[toc] | [prev] | [next] | [standalone]


#21811

FromJames Kuyper <jameskuyper@verizon.net>
Date2012-06-04 07:55 -0400
Message-ID<jqi7n5$i08$1@dont-email.me>
In reply to#21795
On 06/04/2012 05:32 AM, David RF wrote:
> Hi friends:
> Machine epsilon is the maximum relative error of the chosen rounding
> procedure
> 
> #include <stdio.h>
> #include <math.h>
> #include <float.h>
> 
> int main(void)
> {
>   double a = 0.1;
>   double b = 0.1;
> 
>   a += 1.0;
>   a -= 1.0;
> 
>   printf("a == b = %s\n", a == b ? "equals" : "unequals");
>   printf("a == b = %s\n", fabs(a - b) < DBL_EPSILON ? "equals" :
> "unequals");
>   return 0;
> }
> 
> Is this a good method for test the equality?

Not particularly.

First of all, it's not a test for equality, that's simply done in C by
the == operator. It's a test for near-equality. It's seldom correct to
test floating point values for equality with each other; it's sometimes
appropriate to compare them for approximate equality, but you should
always be sure that it actually is appropriate.

The general form for conducting approximate equality tests is

	fabs(a-b) < epsilon

where epsilon will, in general, have different values for different
comparisons.

You correctly described machine epsilon as describing a relative error.
That means that you should not use DBL_EPSILON directly. If the only
source of error in you calculations was a single floating point roundoff
error, you should scale it according to the numbers being compared, by
multiplying it by fabs(a) or fabs(b), whichever is larger.

If multiple floating point errors are involved (as, for instance, with
a+=1.0 and a-=1.0 in your example), then the calculation of the
appropriate value for epsilon gets more complicated. If any of the
quantities you compare are measurements, or numbers calculated from
measurements, measurement error is likely to be much larger than
floating point round-off error.

There's a subject called "propagation of errors" or "propagation of
uncertainty), which is essentially devoted to determining the correct
way of calculating the appropriate value to use for epsilon in such
contexts. The corresponding wikipedia page is at least as good a place
to start learning about that subject as any other.
-- 
James Kuyper

[toc] | [prev] | [next] | [standalone]


#21813

FromDavid RF <davranfor@gmail.com>
Date2012-06-04 04:59 -0700
Message-ID<d52a60ee-4cb5-41ee-895b-3fb788626fe2@c19g2000yqk.googlegroups.com>
In reply to#21811
On 4 jun, 13:55, James Kuyper <jameskuy...@verizon.net> wrote:

[snip ...]
> If multiple floating point errors are involved (as, for instance, with
> a+=1.0 and a-=1.0 in your example), then the calculation of the
> appropriate value for epsilon gets more complicated. If any of the
> quantities you compare are measurements, or numbers calculated from
> measurements, measurement error is likely to be much larger than
> floating point round-off error.

Thanks

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.c


csiph-web