Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Quasi 0 |
| Date | 2012-06-04 14:55 -0700 |
| Organization | None to speak of |
| Message-ID | <lnehpueo7k.fsf@nuthaus.mib.org> (permalink) |
| References | (1 earlier) <jqi0nm$d33$1@dont-email.me> <02098625-5771-48e0-baf6-20f41066edb8@h10g2000yqn.googlegroups.com> <jqi531$4kj$1@dont-email.me> <2a148e85-d20a-4500-bdbc-2bb9a5a134fe@c19g2000yqk.googlegroups.com> <jqi8a7$mlg$1@dont-email.me> |
"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"
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
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
csiph-web