comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: Multiplying fixed-point by long integer
Date: Tue, 6 Nov 2012 12:33:52 -0800 (PST)
Date: 2012-11-06T12:33:52-08:00	[thread overview]
Message-ID: <fe31b386-4eeb-4171-be71-28ed84435be0@googlegroups.com> (raw)
In-Reply-To: <87y5ievea3.fsf@adaheads.sparre-andersen.dk>

On Tuesday, November 6, 2012 9:20:55 AM UTC-8, Jacob Sparre Andersen wrote:
> Adam Beneschan writes: 
> 
> > 4.5.5 defines predefined multiplication operators between any
> > fixed-point type and Integer.  However, it isn't defined for any other
> > integer type.
> 
> Is there a reason for that?  (I can't find anything in the AARM.)

Having it predefined for more than one integer type would lead to ambiguities if you gave it an integer literal, which is probably one of the most common cases.  That is, if F is an object of a fixed-point type, something like

  F := F * 3;

won't compile if "*" were defined multiple times for a fixed-point type and more than one integer type.

The same issue arises with the "**" operator which is predefined only for an Integer right operand.  That shouldn't be a real problem, however, since if N is a value that will fit in a Long_Integer but not an Integer, you're not going to be able to usefully raise anything to the Nth power anyway.

I proposed a suggested solution to Ada-Comment that involved a new language-defined generic, since I didn't want to add to the mess involving predefined fixed-point multiplication and name resolution rules (there have already been some issues with that that probably caused the ARG some headaches).  Tucker pointed out to me that there was a way to get it done without involving predefined floating-point types:

     type Long_Fixed is delta 1.0 range
        Long_Integer'Pos(Long_Integer'First) * 1.0 ..
          Long_Integer'Pos(Long_Integer'Last) * 1.0;

and then use predefined "*" between two fixed-point types, converting the Long_Integer to Long_Fixed.  Seems like a roundabout way of doing things, but probably acceptable given that the need for this is probably pretty uncommon.

                            -- Adam



      reply	other threads:[~2012-11-06 20:33 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
2012-10-05  5:14 ` anon
2012-11-06 17:20 ` Jacob Sparre Andersen
2012-11-06 20:33   ` Adam Beneschan [this message]
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox