Quasi 0

D

David RF

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

Stefan Ram

David RF said:
Is this a good method for test the equality?

To test equality of two double values, use »==«.
(Another question is when or whether this is appropriate.)
 
E

Eric Sosman

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?"
 
D

David RF

El 04/06/2012 05:32 AM, David RF escribió:







Epsilon> de la máquina es el máximo error relativo de redondeo elegido






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
 
J

James Kuyper

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

James Dow Allen

Procedure >>

{>>
Turn >> = 0.1;
Double >> b = 0.1;


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
 
D

David RF

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
 
B

BartC

Eric Sosman said:
On 6/4/2012 5:32 AM, David RF wrote:

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

James Kuyper

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

David RF

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
 
D

David RF

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

Keith Thompson

BartC said:
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.
 
G

Guest

excellent stuff. I must re-read it.
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!
 
J

James Kuyper

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.
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.
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".
 
J

Joe keane

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
 
S

Stefan Ram

James Kuyper said:
People as young as six are learning to program nowadays; possibly
younger.

Six year olds still can actually write a program to
draw a circle, while older children cannot!

(Alan Kay was teaching five-year old children how to
program a circle: They were asked to walk in a circle
and to report what they did. The children would answer
"walk a little and turn a little." After that cognition
they could write a program to draw a circle.

Ten-year old children already knew what a circle is:
"The set of all point, having the same distance to a
center." So they startet to program individual points
starting at a center, which was more complicated; and
the result was non a connected circle but only single
dots.

Fifteen-year old children already knew the formula »r² = x² + y²«.
They tried to draw a circle using that formula, but
failed. (This formula is not a good starting point for such a
program.) Just because of their additional knowledge, it was
actually more difficult or impossible for them to write such a
program. At least that is what Alan Kay said in a video.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top