From: Adam Beneschan <adam@irvine.com>
Subject: Re: Multiplying fixed-point by long integer
Date: Fri, 5 Oct 2012 08:41:02 -0700 (PDT)
Date: 2012-10-05T08:41:02-07:00 [thread overview]
Message-ID: <92e28d54-0c53-4e3a-a312-47a60429d2fe@googlegroups.com> (raw)
In-Reply-To: <k4lnfr$4h3$1@speranza.aioe.org>
On Thursday, October 4, 2012 9:25:33 PM UTC-7, (unknown) wrote:
> Create a 2nd fixed point type big enough to hold your long integer, and
> multiply by that?
You know, I thought of that last night, after I had posted it. But that raises another problem. I assume you're thinking of something like this:
type Long_Fixed is delta 1.0 range Long_Integer'First .. Long_Integer'Last;
F1, F2 : Some_Other_Fixed_Type;
F2 := F1 * Long_Fixed(N);
except that the Long_Fixed declaration isn't legal, because the range bounds have to be of a real type. But how do you get the bounds to be real?
type Long_Fixed is delta 1.0 range Long_Float(Long_Integer'First) ..
Long_Float(Long_Integer'Last);
This isn't right, because it's possible that the largest floating-point type supported by the implementation has a mantissa size smaller than the number of bits in a Long_Integer (or, if you like, Long_Long_Integer or Interfaces.Integer_64), which means that the result won't be exactly right.
This seems like a flaw in the language, that it supports a "universal real" type for static values that can be indefinitely precise, but there's no way to convert a static integer value to a universal real without going through a predefined floating-point type that may be less accurate than the integer.
Of course, the problem at hand could be solved with something like
type Long_Fixed is delta 1.0 range -2.0**(Long_Integer'Size - 1) ..
2.0**(Long_Integer'Size - 1) - 1.0;
Seems a bit hokey that you have to go through this, though.
-- Adam
next prev parent reply other threads:[~2012-10-05 15:41 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-05 1:46 Multiplying fixed-point by long integer Adam Beneschan
2012-10-05 2:12 ` Shark8
2012-10-05 4:23 ` Jeffrey Carter
2012-10-05 4:25 ` tmoran
2012-10-05 15:41 ` Adam Beneschan [this message]
2012-10-05 5:14 ` anon
2012-11-06 17:20 ` Jacob Sparre Andersen
2012-11-06 20:33 ` Adam Beneschan
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox