* Generic_Rational
@ 2018-02-17 11:52 hnptz
2018-02-17 12:33 ` Generic_Rational Simon Wright
2018-02-17 14:13 ` Generic_Rational hnptz
0 siblings, 2 replies; 5+ messages in thread
From: hnptz @ 2018-02-17 11:52 UTC (permalink / raw)
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.
I also used Ada.Numerics.Long_Elementary_Functions.
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?
best,
montgrimpulo
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Generic_Rational
2018-02-17 11:52 Generic_Rational hnptz
@ 2018-02-17 12:33 ` Simon Wright
2018-02-17 14:13 ` Generic_Rational hnptz
1 sibling, 0 replies; 5+ messages in thread
From: Simon Wright @ 2018-02-17 12:33 UTC (permalink / raw)
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Generic_Rational
2018-02-17 11:52 Generic_Rational hnptz
2018-02-17 12:33 ` Generic_Rational Simon Wright
@ 2018-02-17 14:13 ` hnptz
2018-02-17 14:47 ` Generic_Rational Simon Wright
2018-02-17 16:41 ` Generic_Rational Jeffrey R. Carter
1 sibling, 2 replies; 5+ messages in thread
From: hnptz @ 2018-02-17 14:13 UTC (permalink / raw)
Thanks, it's working now. Nevertheless a further question:
Simon wrote
"... 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 ... "
Does a loop from 2..2**15 exceed the bounds of an integer type by one ? (see also 3.5.4(21)). If so, then Candidate should be become a Long_Integer type following 3.6(19). What may be wrong with this interpretation?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Generic_Rational
2018-02-17 14:13 ` Generic_Rational hnptz
@ 2018-02-17 14:47 ` Simon Wright
2018-02-17 16:41 ` Generic_Rational Jeffrey R. Carter
1 sibling, 0 replies; 5+ messages in thread
From: Simon Wright @ 2018-02-17 14:47 UTC (permalink / raw)
hnptz@yahoo.de writes:
> Thanks, it's working now. Nevertheless a further question:
>
> Simon wrote
>
> "... 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 ... "
>
> Does a loop from 2..2**15 exceed the bounds of an integer type by one
> ? (see also 3.5.4(21)). If so, then Candidate should be become a
> Long_Integer type following 3.6(19). What may be wrong with this
> interpretation?
(18) says "If the type of the range resolves to root_integer, then the
discrete_subtype_definition defines a subtype of the predefined type
Integer with bounds given by a conversion to Integer of the bounds of
the range"; and I'm pretty sure that means "the largest integer type
suported by the implementation".
GNAT's Integer is -2**31 .. 2**31 -1 , so 2**15 is well
within. Long_Integer is -2**63 .. 2**63 - 1.
for Candidate in 2..2**31 loop
>>> value not in range of type "Standard.Integer"
>>> static expression fails Constraint_Check
for Candidate in 2..2**63 loop
>>> warning: non-static universal integer value out of range
>>> warning: "Constraint_Error" will be raised at run time
>>> value not in range of type "Standard.Integer"
>>> static expression fails Constraint_Check
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Generic_Rational
2018-02-17 14:13 ` Generic_Rational hnptz
2018-02-17 14:47 ` Generic_Rational Simon Wright
@ 2018-02-17 16:41 ` Jeffrey R. Carter
1 sibling, 0 replies; 5+ messages in thread
From: Jeffrey R. Carter @ 2018-02-17 16:41 UTC (permalink / raw)
On 02/17/2018 03:13 PM, hnptz@yahoo.de wrote:
>
> Does a loop from 2..2**15 exceed the bounds of an integer type by one ? (see also 3.5.4(21)). If so, then Candidate should be become a Long_Integer type following 3.6(19). What may be wrong with this interpretation?
That's the minimum range required of the predefined type Integer. The actual
range is implementation-defined and may be larger. I think the language would be
better if it defined
type Integer is range -(2 ** 15) + 1 .. 2 ** 15 - 1;
and didn't have the optional Short_ and Long_ types.
--
Jeff Carter
"Pray that there's intelligent life somewhere up in
space, 'cause there's bugger all down here on earth."
Monty Python's Meaning of Life
61
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2018-02-17 16:41 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-17 11:52 Generic_Rational hnptz
2018-02-17 12:33 ` Generic_Rational Simon Wright
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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox