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


Groups > comp.lang.c > #16258

Re: zero up memory

From Kleuske <kleuske@nowhere.net>
Newsgroups comp.lang.c
Subject Re: zero up memory
Date 2012-01-26 14:42 +0000
Organization A noiseless patient Spider
Message-ID <jfroo5$egd$3@dont-email.me> (permalink)
References (7 earlier) <40e1a29a-80ab-4b1a-bc54-119f148dd78a@8g2000vbv.googlegroups.com> <4f1f2d6e$0$18693$91cee783@newsreader03.highway.telekom.at> <lnzkdc68c5.fsf@nuthaus.mib.org> <jfp7n3$7gd$6@dont-email.me> <895944d1-8cd9-4f0f-9d82-fef14fd81888@l1g2000vbc.googlegroups.com>

Show all headers | View raw


On Wed, 25 Jan 2012 13:05:53 -0800, Malcolm McLean saw fit to publish the
following:

> On Jan 25, 3:39 pm, Kleuske <kleu...@nowhere.net> wrote:
>>
>> In fact it did, if only in passing. The comparison is a bit-wise one,
>> IIRC, and using '==' for floats and doubles is strongly discouraged
>> where i work.
>>
>> I think it might be a universal best practice.
>>
> If you're comparing reals for equality, usually it means that there's
> something logically wrong in what you're doing, and bunging in a +/-
> epsilon is only masking the problem.

I usually don't use reals at all, only when absolutely required, but that's
another matter.

In fields where they are required, i suppose the logic dictates you first put
your equations in a form that preserves as much precision as possible. But
that's maths. Since you probably have many different calculations, an
appropriate epsilon cannot sensibly be a single constant, since it not only
depends on math applied, but also on the physical tolerances of the input and
any "equality-checking" degrades to checking whether or not something falls in
some specified range, which is a different kettle of fish.

In that way, you are (probably) right.

> But there are exceptions of course. An example would be if you want to
> check that two data items are actually copies of each other.

In one of my hobby projects, however, the user perform math in a toy language,
and, rather than stunning the user with the absence of a equality operator for
reals, decided to implement one using the above method and an epsilon the
user can specify.

-- 
No one wants war.
		-- Kirk, "Errand of Mercy", stardate 3201.7

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

zero up memory "Mark" <mark_cruzNOTFORSPAM@hotmail.com> - 2012-01-23 10:51 -0500
  Re: zero up memory Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-01-23 16:30 +0000
  Re: zero up memory Johann Klammer <klammerj@NOSPAM.a1.net> - 2012-01-23 17:57 +0100
    Re: zero up memory Kenneth Brody <kenbrody@spamcop.net> - 2012-01-23 12:07 -0500
    Re: zero up memory Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-01-23 09:08 -0800
      Re: zero up memory Keith Thompson <kst-u@mib.org> - 2012-01-23 09:22 -0800
        Re: zero up memory Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-01-23 10:13 -0800
          Re: zero up memory Keith Thompson <kst-u@mib.org> - 2012-01-23 12:00 -0800
        Re: zero up memory Kaz Kylheku <kaz@kylheku.com> - 2012-01-23 20:14 +0000
          Re: zero up memory "Joel C. Salomon" <joelcsalomon@gmail.com> - 2012-01-23 16:46 -0500
          Re: zero up memory Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-01-23 14:05 -0800
            Re: zero up memory Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-01-23 23:21 +0000
              Re: zero up memory Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-01-24 09:35 -0800
                Re: zero up memory Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-01-24 20:56 +0000
                Re: zero up memory Keith Thompson <kst-u@mib.org> - 2012-01-24 14:07 -0800
                Re: zero up memory Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-01-25 17:38 +0000
                Re: zero up memory Johann Klammer <klammerj@NOSPAM.a1.net> - 2012-01-24 23:15 +0100
                Re: zero up memory Keith Thompson <kst-u@mib.org> - 2012-01-24 14:31 -0800
                Re: zero up memory Kleuske <kleuske@nowhere.net> - 2012-01-25 15:39 +0000
                Re: zero up memory Kleuske <kleuske@nowhere.net> - 2012-01-25 15:49 +0000
                Re: zero up memory Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-01-26 03:09 -0800
                Re: zero up memory Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-01-25 13:05 -0800
                Re: zero up memory Sjouke Burry <s@b> - 2012-01-25 23:25 +0000
                Re: zero up memory Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-01-26 03:11 -0800
                Re: zero up memory Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-01-26 11:48 -0800
                Re: zero up memory gordonb.p79fg@burditt.org (Gordon Burditt) - 2012-03-12 17:55 -0500
                Re: zero up memory James Kuyper <jameskuyper@verizon.net> - 2012-03-12 22:10 -0400
                Re: zero up memory Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-03-12 23:24 -0400
                Re: zero up memory James Kuyper <jameskuyper@verizon.net> - 2012-03-12 23:53 -0400
                Re: zero up memory gordonb.pu5nu@burditt.org (Gordon Burditt) - 2012-03-13 00:58 -0500
                Re: zero up memory James Kuyper <jameskuyper@verizon.net> - 2012-03-14 11:17 -0400
                Re: zero up memory Keith Thompson <kst-u@mib.org> - 2012-01-26 11:19 -0800
                Re: zero up memory Kleuske <kleuske@nowhere.net> - 2012-01-27 08:13 +0000
                Re: zero up memory Kleuske <kleuske@nowhere.net> - 2012-01-26 14:42 +0000
                Re: zero up memory Keith Thompson <kst-u@mib.org> - 2012-01-25 12:33 -0800
                Re: zero up memory Kleuske <kleuske@nowhere.net> - 2012-01-26 14:12 +0000
                Re: zero up memory James Kuyper <jameskuyper@verizon.net> - 2012-01-24 17:43 -0500
                Re: zero up memory Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-01-24 16:29 -0800
                Re: zero up memory James Kuyper <jameskuyper@verizon.net> - 2012-01-24 21:43 -0500
                Re: zero up memory Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-01-24 23:58 -0800
                Re: zero up memory Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-01-25 17:52 +0000
                Re: zero up memory Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-01-25 17:48 +0000
                Re: zero up memory Robert Wessel <robertwessel2@yahoo.com> - 2012-01-25 12:15 -0600
                Re: zero up memory blp@cs.stanford.edu (Ben Pfaff) - 2012-01-25 10:35 -0800
                Re: zero up memory Robert Wessel <robertwessel2@yahoo.com> - 2012-01-25 17:15 -0600
                Re: zero up memory Robert Wessel <robertwessel2@yahoo.com> - 2012-01-25 17:23 -0600
                Re: zero up memory "BartC" <bc@freeuk.com> - 2012-01-25 23:51 +0000
                Re: zero up memory Robert Wessel <robertwessel2@yahoo.com> - 2012-01-26 18:35 -0600
                Re: zero up memory James Kuyper <jameskuyper@verizon.net> - 2012-01-25 13:17 -0500
          Re: zero up memory Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-01-23 22:55 +0000
      Re: zero up memory jgk@panix.com (Joe keane) - 2012-01-24 20:45 +0000
        Re: zero up memory Keith Thompson <kst-u@mib.org> - 2012-01-24 14:13 -0800

csiph-web