From: Simon Wright <simon@pushface.org>
Subject: Re: Generic_Rational
Date: Sat, 17 Feb 2018 12:33:04 +0000
Date: 2018-02-17T12:33:04+00:00 [thread overview]
Message-ID: <lymv07hk3j.fsf@pushface.org> (raw)
In-Reply-To: e021a833-75f7-4f58-9eb8-eaf44af84fdd@googlegroups.com
hnptz@yahoo.de writes:
> On http://rosettacode.org/wiki/Arithmetic/Rational/Ada there is an
> Ada-package which is OK as it is. It says that the package can be
> instantiated with any integer type. However, I tried to instantiate it
> with Long_Integer.
And the instantiation compiles fine.
> I also used Ada.Numerics.Long_Elementary_Functions.
There was no need for that.
> Now, the Test_Rational programm does not work anymore. The function
> "/" is perhaps not in compliance with Long_Integer. I wonder if the
> declarative part in Test_Rational has a false effect.
>
> What are your suggestions to make it working for Long_Integer numbers
> as well?
When the test program says
for Candidate in 2..2**15 loop
Candidate is of type Integer (see ARM 3.6(17..18)[1], so that when it
says
Sum : Rational := 1 / Candidate;
there would need to be a function
function "/" (L, R : Integer) return Rational
but the only "/" that returns Rational and takes integer types takes
Long_Integers.
Recast the loop as
for Candidate in Long_Integer'(2)..2**15 loop
or
for Candidate in Long_Integer range 2..2**15 loop
and now there's a similar problem with
for Divisor in 2..Integer (Sqrt (Float (Candidate))) loop
...
[1] http://www.ada-auth.org/standards/rm12_w_tc1/html/RM-3-6.html#p17
next prev parent reply other threads:[~2018-02-17 12:33 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-17 11:52 Generic_Rational hnptz
2018-02-17 12:33 ` Simon Wright [this message]
2018-02-17 14:13 ` Generic_Rational hnptz
2018-02-17 14:47 ` Generic_Rational Simon Wright
2018-02-17 16:41 ` Generic_Rational Jeffrey R. Carter
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox