Prev: Dhrystone
Next: Learning Ada
From: Ada novice on 6 Aug 2010 08:03 On Aug 6, 11:49 am, Peter Hermann <h...(a)h.de> wrote: > Jacob Sparre Andersen <ja...(a)jacob-sparre.dk> wrote: > > > type My_Float is digits 18; > > 14 will run everywhere, > 18 not. > > ph Is this because all (modern) platforms/architectures can easily provide for 14 but not for 18? Most likely, all 32-bit Intel machines are able to provide for 18. Am I right? YC
From: Ada novice on 6 Aug 2010 08:04 On Aug 6, 11:51 am, "Dmitry A. Kazakov" <mail...(a)dmitry-kazakov.de> wrote: > > Because it does not tell anything about My_Float. When you declare a > subtype you should have a reason for it. The only reason is putting a > constraint on it. (Another might be type renaming, but that is an Ada > kludge) > > > What about "type My_Float is digits 18" as Jacob Sparre Andersen said > > in an earlier message? > > If you wanted a type of defined accuracy. > > It depends on what you want to achieve: > > 1. Constraining -> Subtype > > 2. Requiring certain accuracy/precision -> Type > > 3. Interfacing -> A type from some library package like Interfaces.C > > 4. Separation of domains (e.g. measurement units etc) -> Type > > 5. Type extension, reimplementation -> type T is private; and in the > private part: type T is new Float; > > > But sjw in an earlier message > > mentions that the "internals of the matrix operations only use 64 > > bits. So in any case then asking for more than Long-Float precision is > > not "relevant". > > That would be the case 3. > Thanks for the explanations. YC
From: Simon Wright on 6 Aug 2010 12:41 Jacob Sparre Andersen <jacob(a)jacob-sparre.dk> writes: > Ada novice <posts(a)gmx.us> wrote: > >> Can we change the subtype to Long_Long_Float? This will be of 18 >> precision digits [...] > > That's not guaranteed. If you want 18 digits, you should declare the > type (My_Float?) as: > > type My_Float is digits 18; And if you build on a PowerPC Mac the compiler will refuse because that precision isn't implemented.
From: Simon Wright on 6 Aug 2010 12:49 "Dmitry A. Kazakov" <mailbox(a)dmitry-kazakov.de> writes: > On Fri, 06 Aug 2010 10:04:24 +0200, Jacob Sparre Andersen wrote: > >> Ada novice <posts(a)gmx.us> wrote: >> >>> Can we change the subtype to Long_Long_Float? This will be of 18 >>> precision digits [...] >> >> That's not guaranteed. If you want 18 digits, you should declare the >> type (My_Float?) as: >> >> type My_Float is digits 18; > > Further, practically you should never use subtype in the form > > subtype My_Float is Long_Float; > > except for special cases like: > > subtype Non_IEEE_Float is Long_Float range Long_Float'Range; > > or > > subtype Non_Negative_Float is Long_Float range 0.0..Long_Float'Last; Depends what you mean by "practically". The thought process was, "I'm going to be writing a set of demo cases which should work for arbitrary floating-point types, I'll call the type My_Float. Shall I use type My_Float is new ... or subtype My_Float is ....? Doesn't really matter, go for subtype."
From: Dmitry A. Kazakov on 6 Aug 2010 13:27
On Fri, 06 Aug 2010 17:49:14 +0100, Simon Wright wrote: > "Dmitry A. Kazakov" <mailbox(a)dmitry-kazakov.de> writes: > >> On Fri, 06 Aug 2010 10:04:24 +0200, Jacob Sparre Andersen wrote: >> >>> Ada novice <posts(a)gmx.us> wrote: >>> >>>> Can we change the subtype to Long_Long_Float? This will be of 18 >>>> precision digits [...] >>> >>> That's not guaranteed. If you want 18 digits, you should declare the >>> type (My_Float?) as: >>> >>> type My_Float is digits 18; >> >> Further, practically you should never use subtype in the form >> >> subtype My_Float is Long_Float; >> >> except for special cases like: >> >> subtype Non_IEEE_Float is Long_Float range Long_Float'Range; >> >> or >> >> subtype Non_Negative_Float is Long_Float range 0.0..Long_Float'Last; > > Depends what you mean by "practically". > > The thought process was, "I'm going to be writing a set of demo cases > which should work for arbitrary floating-point types, I'll call the type > My_Float. Shall I use type My_Float is new ... or subtype My_Float is > ...? Doesn't really matter, go for subtype." I am not sure what do you mean. If the code meant to be used with any type, then it should be generic (My_Float is digits <>). If the code is to work with some yet unknown type (to be determined later) then it should be My_Float is new Long_Float. That would protect me from mixing Long_Float and My_Float. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de |