From: Glynn Clements <glynn@gclements.plus.com>
To: Shriramana Sharma <samjnaa@gmail.com>
Cc: Linux C Programming List <linux-c-programming@vger.kernel.org>
Subject: Re: Integer arithmetic vs double precision arithmetic
Date: Mon, 27 Mar 2006 02:02:53 +0100 [thread overview]
Message-ID: <17447.14781.949111.245955@cerise.gclements.plus.com> (raw)
In-Reply-To: <200603270505.42464.samjnaa@gmail.com>
Shriramana Sharma wrote:
> > Floating-point is meant for the situation where you want a constant
> > relative error rather than a constant absolute error. For timescales,
> > a constant absolute error is usually more useful.
>
> Could you clarify that a bit? How do you mean "constant relative error" as
> against "constant absolute error"?
Absolute error is the difference between the actual value and the
recorded value. Relative error is the absolute error divided by the
actual value.
E.g. suppose that you store a time as an integral number of seconds.
The absolute error is half a second. If the actual time is 10 seconds,
the relative error is 0.05 (5%); if the actual time is 31536000
seconds (365 days), the relative error is approximately 1.6E-08.
OTOH, if you stored the number of seconds as a floating-point value,
the relative error will always be around 1.2E-07 (single precision) or
2.2E-16 (double precision). The absolute error will vary according to
the value stored, e.g. for single precision, for an actual value of
around 1 second, the absolute error will be around 12us, while for an
actual value of around a year, the absolute error will be around 3.8
seconds.
In general, if you are dealing with values of a fixed magnitude, an
integer type will give better precision than a floating-point type of
the same size, because the floating point type uses some of the bits
to store the exponent. If you fix the exponent (i.e. use a common
scale factor), you can use all 32 or 64 bits to store the mantissa.
For measuring absolute time (i.e. time since "year zero", as opposed
to time intervals), you usually want values which are accurate to
within some fixed interval (e.g. 1s, 1ms, 1us etc), rather than values
which are highly accurate close to the beginning of the timescale but
which get less accurate as time goes on.
E.g. The Unix API uses either seconds since midnight UTC, Jan 1st 1970
(time(), typically 32 bits) or seconds and microseconds since that
time (gettimeofday(), typically 32 bits for each component), while
Java uses milliseconds since that date (64 bits).
--
Glynn Clements <glynn@gclements.plus.com>
next prev parent reply other threads:[~2006-03-27 1:02 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-03-26 15:14 Integer arithmetic vs double precision arithmetic Shriramana Sharma
2006-03-26 16:12 ` Steve Graegert
2006-03-26 16:24 ` Shriramana Sharma
2006-03-26 21:03 ` Glynn Clements
2006-03-26 23:35 ` Shriramana Sharma
2006-03-27 1:02 ` Glynn Clements [this message]
2006-03-27 8:32 ` Shriramana Sharma
2006-03-27 17:13 ` Glynn Clements
2006-03-26 16:12 ` Glynn Clements
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=17447.14781.949111.245955@cerise.gclements.plus.com \
--to=glynn@gclements.plus.com \
--cc=linux-c-programming@vger.kernel.org \
--cc=samjnaa@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).