J
James Kuyper
Keith said:Close, but ...
Yep, sorry for the typo.
Keith said:Close, but ...
Golden said:Last I checked PI was irrational and therefore not something that it was claimed
to be able to compute exactly.
CBFalconer said:Flash Gordon wrote:
.... snip ...
The critical point here is what does sin(11) return.
If it returns
a double, then you can safely assume that x holds the value that
sin(11) will return in future (assuming sin is a single valued
function).
If you assert that sin(11) returns the sin of an angle
of 11 degrees, there are two accuracies involved. One is the
accuracy of the sin function. It is pointless arranging an
algorithm that could return values more accurate than that of the
double (assuming it is returning a double).
I think the C restrictions are such that we can assume sin returns
a single valued function representing the sine of an angle TO SOME
ACCURACY.![]()
Golden California Girls said:You do know the problem you were attempting to solve ...
Keith said:Golden California Girls said:(s/konw/know/
Once again what gets stored (domain of representable values) has
little if any relation to what should have been stored (domain of
real numbers).
Perhap, but (a) how do you know what *should* have been stored* and
(b) we were discussing what actually *is* stored.
[snip]
Every new programmer should be taught this until it sinks in, then
they can take a class in numeric analysis and realize that any
floating point number in base 2 is always just one possibility out
of a range, that being from that number to the upper error bound
down to the number less the lower error bound. Then they will
understand one of the truths of the universe that if a floating
point number turns out to be correct it is a miracle and the counter
example to Murphy's law.
Or it's a result of careful programming and analysis.
double x = 1.0;
x contains exactly what I want it to. In this particular case, there
is no error.
Keith said:.... snip ...
If I write:
double y = 1.0/3.0;
the value that's *supposed* to be stored in y is a close approximation
to the mathematical value one-third. My expectations are not always
entirely realistic, but they usually bear some resemblance to what's
actually possible.
Flash Gordon said:Pi may be irrational, but any algorithm in C will be calculating
rational approximations. At some point your rational approximation of
Pi will not be representable in the finite amount of memory available
for it to run.
CBFalconer said:Keith Thompson wrote: [...]You konw exactly what value was stored. (You don't necessarily know
how that value was computed.)
Once again, C99 6.2.4p2:
An object exists, has a constant address, and retains its
last-stored value throughout its lifetime.
And again, that last-stored 'value' is a range.
Richard Heathfield said:Eric Sosman said:
CBFalconer said:[...] In particular rationals, reals,
integers can all be put in one to one correspondence with the set
of integers. [...]
Nonsense. The integers are 1-1 with the integers, and
the integers are 1-1 with the rationals. But the integers
are *not* 1-1 with the reals. Look up "diagonal argument,"
and try to refrain from posting about what you wot not.
Briefly, Cantor's diagonal argument runs as follows (although this
explanation is obviously subject to corrections by real
mathematicians!).
1) We assume that the reals are countable. That is, there may be
infinitely many of them, but they can be placed into one-to-one
correspondence with the integers. That is, we assume that CBF is
right. (This is known as reductio ad absurdum.)
2) We imagine a COMPLETE list L of the reals (an infinitely long
list, obviously, but it is complete in the sense that it contains
one entry for every integer - i.e. is in one-to-one correspondence
with the integers), in numerical order (actually any order will do,
but it may help to think of them as being ordered). Each list entry
corresponds to an integer - its position on the list. They are
lined up such that the first decimal place of each is in one
column, the next decimal place is in the next column, etc. We can
address the i'th entry as L, and the j'th decimal place of the
i'th number as L[j].
3) It is now easy to demonstrate that a real number exists that is
not on this (infinitely long) list:
for(i = 0; i < infinity; i++)
{
new = 9 - L;
}
This loop constructs a new real number that must be different from
each of the numbers in the list. When it eventually completes
(don't hold your breath), the number it has constructed is bound to
differ from every other number in the list by at least one position
(position i for the i'th real number on the list). We have
therefore demonstrated that the list is not complete. (And if we
add it to the list, we just run the loop again and come up with
another such number.) This contradicts our original assumption,
which is true if the reals are countable. Therefore, they are not.
Incidentally, this is even more obvious in binary, with the slight
mod to the loop:
for(i = 0; i < infinity; i++)
{
new = 1 - L;
}
Keith said:CBFalconer said:Keith Thompson wrote: [...]You konw exactly what value was stored. (You don't necessarily
know how that value was computed.)
Once again, C99 6.2.4p2:
An object exists, has a constant address, and retains its
last-stored value throughout its lifetime.
And again, that last-stored 'value' is a range.
No, it is not a range, it is a single value.
If it were intended to be a range, surely the standard would say
so in 5.2.4.2.2, "Characteristics of floating types <float.h>".
That section, particularly the first two paragraphs, defines C's
model for floating-point numbers. It uses the word "range"
several times, but never in reference to a stored value. The
model in paragraph 2 defines a single value, not a range.
Have you read C99 5.2.4.2.2 paragraphs 1 and 2?
Flash said:.... snip ...
You have also completely ignored the fact that I have presented
situations where the integer types *are* used as approximations.
So, is int just an approximation?
CBFalconer said:Keith Thompson wrote: [...]Have you read C99 5.2.4.2.2 paragraphs 1 and 2?
Because they don't affect the argument. All stored FP values are
ranges. Note p.3:
[#3] Floating types may include values that are not
normalized floating-point numbers, for example subnormal
floating-point numbers (x!=0,e=emin,f1=0), infinities, and
NaNs.15) A NaN is an encoding signifying Not-a-Number. A
quiet NaN propagates through almost every arithmetic
operation without raising an exception; a signaling NaN
generally raises an exception when occurring as an
arithmetic operand.16)
which does not limit the anomalies to the given examples.
>
> Did you deliberately ignore the algebra I posted? It had - ex -
> ey, but recommended ignoring the term in ex*ey.
Once again what gets stored (domain of representable values) has little if any
relation to what should have been stored (domain of real numbers).
The standard permits an infinite amount of error.
bollocks
For instance it permits zero
to be stored for the real number 1^-10^100,
however there are an infinite number
of real values between that number and zero hence infinite error!
Note that my
representation of the number is exact and uses 9 bytes. C using base 2 in 16
bytes of a long double gets it infinitely wrong. A slightly longer exact human
readable form is 1/googolplex or 12 bytes.
Every new programmer should be taught this until it sinks in,
please said:then they can take a class in numeric analysis
and realize that any floating point number in base 2
is always just one possibility out of a range, that being from that number to
the upper error bound down to the number less the lower error bound. Then they
will understand one of the truths of the universe that if a floating point
number turns out to be correct it is a miracle and the counter example to
Murphy's law.
Please provide an example showing that the set of FP values is *not* closedNo, although it may be so used. It is intended to handle integers,
and, except for division, the set of integers is closed under
elementary arithmetic. People are quite familiar with the idea
that a division results in a quotient and a remainder, under which
condition the integer set remains closed.
You can't make these statements about FP values.
Doug said:Please provide an example showing that the set of FP values is *not* closed
under elementary arithmetic.
Please provide an example showing that the set of FP values is *not* closed
under elementary arithmetic.
Dik T. Winter said:Did you deliberately ignore what I wrote? I wrote: "the bounds of the
range are *not* eps(x * y), but eps(x + y)". Sheesh.
Richard said::
.... snip ...
I'm sorry, but it seems to me that you are castigating cbf (in
itself quite the rage these days) quite unfairly. I know what he
is doing; he is deriving the extent of the bounds of the range of
x*y and showing that it is the same as the extent of the bounds
of x+y.
Keith said:CBFalconer said:Keith Thompson wrote: [...]Have you read C99 5.2.4.2.2 paragraphs 1 and 2?
Because they don't affect the argument. All stored FP values are
ranges. Note p.3:
[#3] Floating types may include values that are not
normalized floating-point numbers, for example subnormal
floating-point numbers (x!=0,e=emin,f1=0), infinities, and
NaNs.15) A NaN is an encoding signifying Not-a-Number. A
quiet NaN propagates through almost every arithmetic
operation without raising an exception; a signaling NaN
generally raises an exception when occurring as an
arithmetic operand.16)
which does not limit the anomalies to the given examples.
So what? I don't see the word "range" in that paragraph, or anything
even vaguely implying that a stored floating-point value represents a
range.
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.