* type declaration and storage requirements @ 2002-06-02 21:21 Russ 2002-06-02 23:54 ` martin.m.dowie ` (3 more replies) 0 siblings, 4 replies; 15+ messages in thread From: Russ @ 2002-06-02 21:21 UTC (permalink / raw) Ada allows me to specify the number of digits and the range of a floating-point type, or the delta and range of a fixed-point type. This gives more control than, say, C/C++, which only allows me to specify single or double precision. What bothers me, however, is that I apparently need to do some homework of my own to determine if my declaration will require one or two words for storage (for a particular word size). Suppose I have a particular range in mind, and I just want to get the maximum number of digits I can get for, say, a 32-bit word. Is there a simple way to determine how many digits to specify? If I specify one digit too many, can it step the storage requirement from one to two words? I'm no expert, but it seems to me that what you really want to be able to specify is not the number of digits but rather the total number of bytes to be used. Also, suppose I specify one digit too many for single-word storage. I presume I will get double-word storage and nearly double the precision I asked for. If I then port the program to another machine with a different word size, I may get less precision, which means that the program may produce different results. Am I missing something here? I guess Ada takes the view that storage requirements are secondary to the application's actual precision requirements. That's certainly valid to a point, I guess. But sometimes precision requirements are not so precise themselves, and jumping from one to two words might be undesirable, particularly if the type is to be used extensively. ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: type declaration and storage requirements 2002-06-02 21:21 type declaration and storage requirements Russ @ 2002-06-02 23:54 ` martin.m.dowie 2002-06-03 0:40 ` Dale Stanbrough 2002-06-03 6:58 ` Russ 2002-06-03 2:26 ` Jeffrey Carter ` (2 subsequent siblings) 3 siblings, 2 replies; 15+ messages in thread From: martin.m.dowie @ 2002-06-02 23:54 UTC (permalink / raw) "Russ" <18k11tm001@sneakemail.com> wrote in message news:bebbba07.0206021321.a3bbfac@posting.google.com... > Ada allows me to specify the number of digits and the range of a > floating-point type, or the delta and range of a fixed-point type. > This gives more control than, say, C/C++, which only allows me to > specify single or double precision. What bothers me, however, is that > I apparently need to do some homework of my own to determine if my > declaration will require one or two words for storage (for a > particular word size). [snip] I think the argument here is - "Why do you care?" The only time you care about such things are when you are defining interfacing and usually there will be an IDD to define such things (or else there isn't and, yes, you may be the person assigned to think about such size issues - but that is not a language issue). ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: type declaration and storage requirements 2002-06-02 23:54 ` martin.m.dowie @ 2002-06-03 0:40 ` Dale Stanbrough 2002-06-03 11:10 ` martin.m.dowie 2002-06-03 6:58 ` Russ 1 sibling, 1 reply; 15+ messages in thread From: Dale Stanbrough @ 2002-06-03 0:40 UTC (permalink / raw) In article <hfyK8.40339$wd3.6272305@news6-win.server.ntlworld.com>, "martin.m.dowie" <martin.m.dowie@ntlworld.com> wrote: > I think the argument here is - "Why do you care?" > > The only time you care about such things are when you are defining > interfacing > and usually there will be an IDD to define such things (or else there isn't > and, > yes, you may be the person assigned to think about such size issues - but > that > is not a language issue). I'm not sure if i've got the wrong end of the stick here, but it seems to me that it -is- a language issue, because the Ada designers have deemed to put it -into- the language. You can argue about whether it is the right decision (and you seem to be arguing against that). I would disagree - for some languages it makes sense to go to the trouble to include this information, as it may make writing portable programs easier. Dale ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: type declaration and storage requirements 2002-06-03 0:40 ` Dale Stanbrough @ 2002-06-03 11:10 ` martin.m.dowie 2002-06-04 2:40 ` Dale Stanbrough 0 siblings, 1 reply; 15+ messages in thread From: martin.m.dowie @ 2002-06-03 11:10 UTC (permalink / raw) "Dale Stanbrough" <dale@cs.rmit.edu.au> wrote in message news:dale-09A130.10404303062002@its-aw-news.its.rmit.edu.au... > In article <hfyK8.40339$wd3.6272305@news6-win.server.ntlworld.com>, [snip] > I'm not sure if i've got the wrong end of the stick here, but it seems > to me that it -is- a language issue, because the Ada designers have > deemed to put it -into- the language. Sorry, could have been clearer. IDD's are language independent was what I was driving at. > You can argue about whether it is the right decision (and you seem to > be arguing against that). I would disagree - for some languages it makes > sense to go to the trouble to include this information, as it may make > writing portable programs easier. No - I totally want be be able to control underlying representation when I'm defining messages that must go over particular interfaces (e.g. ethernet, 1553, etc). But for types that are solely for use to the internals of my program 99 times out of a 100 I don't care, provided that I've defined my 'digits' or 'delta' or 'ranges' correctly. I will admit that I use record representations less and less as the years go by and just do explicit byte array => internal representations by hand (with the help of a few generics). I've always found this area to be one of the most troublesome as far as portability goes... ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: type declaration and storage requirements 2002-06-03 11:10 ` martin.m.dowie @ 2002-06-04 2:40 ` Dale Stanbrough 0 siblings, 0 replies; 15+ messages in thread From: Dale Stanbrough @ 2002-06-04 2:40 UTC (permalink / raw) martin.m.dowie wrote: > But for types that are solely for use to the internals of my program 99 > times > out of a 100 I don't care, provided that I've defined my 'digits' or 'delta' > or > 'ranges' correctly. > > I will admit that I use record representations less and less as the years go > by > and just do explicit byte array => internal representations by hand (with > the > help of a few generics). I've always found this area to be one of the most > troublesome as far as portability goes... :-) i've always wondered (based on the problems that many of the language designers have had formally explaining chapter 13 features) just whether Ada currently sits on the right side of the cost/benefit relationship. Dale ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: type declaration and storage requirements 2002-06-02 23:54 ` martin.m.dowie 2002-06-03 0:40 ` Dale Stanbrough @ 2002-06-03 6:58 ` Russ 2002-06-03 7:57 ` AG ` (3 more replies) 1 sibling, 4 replies; 15+ messages in thread From: Russ @ 2002-06-03 6:58 UTC (permalink / raw) "martin.m.dowie" <martin.m.dowie@ntlworld.com> wrote in message news:<hfyK8.40339$wd3.6272305@news6-win.server.ntlworld.com>... > "Russ" <18k11tm001@sneakemail.com> wrote in message > news:bebbba07.0206021321.a3bbfac@posting.google.com... > > Ada allows me to specify the number of digits and the range of a > > floating-point type, or the delta and range of a fixed-point type. > > This gives more control than, say, C/C++, which only allows me to > > specify single or double precision. What bothers me, however, is that > > I apparently need to do some homework of my own to determine if my > > declaration will require one or two words for storage (for a > > particular word size). > [snip] > > I think the argument here is - "Why do you care?" Why do I care about how much storage I use? Maybe I'm just obsessive, but I would like to know if I am using single or double precision. Is that so unreasonable? > The only time you care about such things are when you are defining > interfacing > and usually there will be an IDD to define such things (or else there isn't > and, > yes, you may be the person assigned to think about such size issues - but > that > is not a language issue). I don't care what kind of "issue" you want to label it. I just want to know whether I am using single or double precision. And what is the point of specifying the number of digits if the compiler is just going to choose one or two words? If I choose less than 7 digits, I probably get single precision, but if I choose 7 (8?) or more I probably get double precision. It's like going to a bank where they ask you, "What is the minimum amount of money you wish to withdraw?" If you ask for $100 or less, you get $100, but if you ask for more than $100, you get $200. What is the point of pretending that you get to specify the amount precisely if you don't? Wouldn't it make more sense to just ask if you want $100 or $200? ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: type declaration and storage requirements 2002-06-03 6:58 ` Russ @ 2002-06-03 7:57 ` AG 2002-06-03 11:19 ` martin.m.dowie ` (2 subsequent siblings) 3 siblings, 0 replies; 15+ messages in thread From: AG @ 2002-06-03 7:57 UTC (permalink / raw) "Russ" <18k11tm001@sneakemail.com> wrote in message news:bebbba07.0206022258.5653ecac@posting.google.com... > "martin.m.dowie" <martin.m.dowie@ntlworld.com> wrote in message news:<hfyK8.40339$wd3.6272305@news6-win.server.ntlworld.com>... > > "Russ" <18k11tm001@sneakemail.com> wrote in message > > news:bebbba07.0206021321.a3bbfac@posting.google.com... > > > Ada allows me to specify the number of digits and the range of a > > > floating-point type, or the delta and range of a fixed-point type. > > > This gives more control than, say, C/C++, which only allows me to > > > specify single or double precision. What bothers me, however, is that > > > I apparently need to do some homework of my own to determine if my > > > declaration will require one or two words for storage (for a > > > particular word size). > > [snip] > > > > I think the argument here is - "Why do you care?" If that were the case the argument would be - "why is it in the language?" Presumably, the must be a reason ... > > Why do I care about how much storage I use? Maybe I'm just obsessive, > but I would like to know if I am using single or double precision. Is > that so unreasonable? It's been some time since I had to really dig into the Ada 83 concept of model and safe numbers as defined for both float and fixed types. But I seem to recall that at least *some* changes in 95 standard in that area were exactly due to the fact that some model numbers forced a double-word implementation where a single-word would suffice. Anyone with a beter knowledge of the issue would care to comment? [I'm serious about that - would be really interesting and, perhaps, illuminating in this context] > > > The only time you care about such things are when you are defining > > interfacing Or, maybe, when you are defining a matrix about 2Gb large. Or, more likely, when you care about some obscure math properties of the numbers. > > yes, you may be the person assigned to think about such size issues - but > > that > > is not a language issue). It is the language issue exactly (or maybe it's Annex). So what do you do if you *are* the person assigned to think about such issues? Sort of need to know what the language says, right? > > I don't care what kind of "issue" you want to label it. I just want to > know whether I am using single or double precision. And what is the > point of specifying the number of digits if the compiler is just going > to choose one or two words? If I choose less than 7 digits, I probably > get single precision, but if I choose 7 (8?) or more I probably get > double precision. Well, again, I didn't need to use real numbers in Ada since 83 model but as I recall they were defined as a minimum power of two which satisfies the requirements with no regard or even a concept of a single or double precision. [And yes, there were custom-sized deltas too] ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: type declaration and storage requirements 2002-06-03 6:58 ` Russ 2002-06-03 7:57 ` AG @ 2002-06-03 11:19 ` martin.m.dowie 2002-06-03 12:40 ` Larry Kilgallen 2002-06-03 13:12 ` Gautier 3 siblings, 0 replies; 15+ messages in thread From: martin.m.dowie @ 2002-06-03 11:19 UTC (permalink / raw) "Russ" <18k11tm001@sneakemail.com> wrote in message news:bebbba07.0206022258.5653ecac@posting.google.com... > > [snip] > > > > I think the argument here is - "Why do you care?" > > Why do I care about how much storage I use? Maybe I'm just obsessive, > but I would like to know if I am using single or double precision. Is > that so unreasonable? No, but I tend to just try and ensure I've got the ranges/digits/delta/alignments ok and let the compiler choose what is most optimal. Even in the embedded systems I work in, actual underlying representations of internal types/objects comes way down my list of 'this to check for inefficiencies'. I'll repeat my caveat - "except when I'm defining messages for external interfaces" > I don't care what kind of "issue" you want to label it. I just want to > know whether I am using single or double precision. And what is the > point of specifying the number of digits if the compiler is just going > to choose one or two words? If I choose less than 7 digits, I probably > get single precision, but if I choose 7 (8?) or more I probably get > double precision. If you choose 7 digits the compiler will give you a size that will accomodate that. My understanding is that it would be free to give you double precision if it deemed that the most efficient for the particular target. > It's like going to a bank where they ask you, "What is the minimum > amount of money you wish to withdraw?" If you ask for $100 or less, > you get $100, but if you ask for more than $100, you get $200. What is > the point of pretending that you get to specify the amount precisely > if you don't? Wouldn't it make more sense to just ask if you want $100 > or $200? No I don't think it is like that. My view of Ada typing is that it offers an 'abstract view' rather than absolute underlying representations (unless that is what you specify). The compiler will always ensure that your minimum requirements are met but that it is free to 'actually' implement it in prett y much anyway it sees fit. ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: type declaration and storage requirements 2002-06-03 6:58 ` Russ 2002-06-03 7:57 ` AG 2002-06-03 11:19 ` martin.m.dowie @ 2002-06-03 12:40 ` Larry Kilgallen 2002-06-03 13:12 ` Gautier 3 siblings, 0 replies; 15+ messages in thread From: Larry Kilgallen @ 2002-06-03 12:40 UTC (permalink / raw) In article <bebbba07.0206022258.5653ecac@posting.google.com>, 18k11tm001@sneakemail.com (Russ) writes: > "martin.m.dowie" <martin.m.dowie@ntlworld.com> wrote in message news:<hfyK8.40339$wd3.6272305@news6-win.server.ntlworld.com>... >> "Russ" <18k11tm001@sneakemail.com> wrote in message >> news:bebbba07.0206021321.a3bbfac@posting.google.com... >> > Ada allows me to specify the number of digits and the range of a >> > floating-point type, or the delta and range of a fixed-point type. >> > This gives more control than, say, C/C++, which only allows me to >> > specify single or double precision. What bothers me, however, is that >> > I apparently need to do some homework of my own to determine if my >> > declaration will require one or two words for storage (for a >> > particular word size). >> [snip] >> >> I think the argument here is - "Why do you care?" > > Why do I care about how much storage I use? Maybe I'm just obsessive, > but I would like to know if I am using single or double precision. Is > that so unreasonable? I haven't followed the entire discussion, but I presume this is for use in portable programming where one cannot just look at the machine and compiler documentation. If you specified single or double precision, what would you do on VAX, where you have a choice of three precisions ? Do you always mean "smallest" and "largest" when you say single and double ? What would you say to get the other one - "middle" ? If that is the case, what happens when you move that program from VAX to some other system where there are only two choices ? What would happen to those where you specified "middle" is that a "middle if you have it but otherwise smallest" or would you prefer "middle if you have it but otherwise largest"? Of course dedicated VAX fans remember that there are two different 64-bit floating point types, D and G. The different between them is their mantissa and exponent, math thingies that have to do with range and precision supported by the hardware. Now we could all specify floating point types in terms of the VAX precisions, F, G, D and H, but that raised complications when Alpha came along with S and T floating point types, so on Alpha VMS supports 5 types (I forget which one they dropped). So even specifying you want 32 bit or 64 bit floating point types does not nail it down. ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: type declaration and storage requirements 2002-06-03 6:58 ` Russ ` (2 preceding siblings ...) 2002-06-03 12:40 ` Larry Kilgallen @ 2002-06-03 13:12 ` Gautier 3 siblings, 0 replies; 15+ messages in thread From: Gautier @ 2002-06-03 13:12 UTC (permalink / raw) Russ: > It's like going to a bank where they ask you, "What is the minimum > amount of money you wish to withdraw?" If you ask for $100 or less, > you get $100, but if you ask for more than $100, you get $200. What is > the point of pretending that you get to specify the amount precisely > if you don't? Wouldn't it make more sense to just ask if you want $100 > or $200? In that case you choose Float or Long_Float and you are happy, don't you ? Well, are there specifications about Float and Long_Float in the Manual ? BTW, your bank dialogue can be simulated by trying to compile with some precision, see what the compiler finds and adjust according to a precision/storage trade-off convenient to you. ________________________________________________________ Gautier -- http://www.mysunrise.ch/users/gdm/gsoft.htm NB: For a direct answer, address on the Web site! ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: type declaration and storage requirements 2002-06-02 21:21 type declaration and storage requirements Russ 2002-06-02 23:54 ` martin.m.dowie @ 2002-06-03 2:26 ` Jeffrey Carter 2002-06-04 10:35 ` Simon Wright 2002-06-11 7:18 ` David Thompson 3 siblings, 0 replies; 15+ messages in thread From: Jeffrey Carter @ 2002-06-03 2:26 UTC (permalink / raw) Russ wrote: > > Ada allows me to specify the number of digits and the range of a > floating-point type, or the delta and range of a fixed-point type. > This gives more control than, say, C/C++, which only allows me to > specify single or double precision. What bothers me, however, is that > I apparently need to do some homework of my own to determine if my > declaration will require one or two words for storage (for a > particular word size). You should define your own types when the precision and range are application defined and important, and the specific representation is not. "digits X" only specifies a minimum precision; the actual representation may give you more. If the representation is important and the precision is not, then you probably need the types defined in package Interfaces. -- Jeff Carter "Oh Lord, bless this thy hand grenade, that with it thou mayst blow thine enemies to tiny bits, in thy mercy." Monty Python and the Holy Grail ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: type declaration and storage requirements 2002-06-02 21:21 type declaration and storage requirements Russ 2002-06-02 23:54 ` martin.m.dowie 2002-06-03 2:26 ` Jeffrey Carter @ 2002-06-04 10:35 ` Simon Wright 2002-06-04 13:04 ` Martin Dowie 2002-06-11 7:18 ` David Thompson 3 siblings, 1 reply; 15+ messages in thread From: Simon Wright @ 2002-06-04 10:35 UTC (permalink / raw) 18k11tm001@sneakemail.com (Russ) writes: > Suppose I have a particular range in mind, and I just want to get > the maximum number of digits I can get for, say, a 32-bit word. Is > there a simple way to determine how many digits to specify? If I > specify one digit too many, can it step the storage requirement from > one to two words? I'm no expert, but it seems to me that what you > really want to be able to specify is not the number of digits but > rather the total number of bytes to be used. If your requirement is to specify a size for the values, say type My_Short_Float_Type is new Float; type My_Long_Float_Type is new Long_Float; or subtype My_Short_Float_Type is Float; subtype My_Long_Float_Type is Long_Float; which are pretty likely to map to C float and double. If on the other hand your requirement is to specify the precision your algorithm requires, you really do need type My_Float_Type is digits 7; and if it turns out that that needs 8 bytes (ie double), so be it. ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: type declaration and storage requirements 2002-06-04 10:35 ` Simon Wright @ 2002-06-04 13:04 ` Martin Dowie 2002-06-06 8:06 ` Simon Wright 0 siblings, 1 reply; 15+ messages in thread From: Martin Dowie @ 2002-06-04 13:04 UTC (permalink / raw) "Simon Wright" <simon@pushface.org> wrote in message news:x7vptz79vr7.fsf@pushface.org... > If your requirement is to specify a size for the values, say > > type My_Short_Float_Type is new Float; > type My_Long_Float_Type is new Long_Float; > > or > > subtype My_Short_Float_Type is Float; > subtype My_Long_Float_Type is Long_Float; > > which are pretty likely to map to C float and double. or use Interfaces.C.C_Float and Interfaces.C.Double to be sure to match C, or Interfaces.Integer_16, Interfaces.Integer_32 to avoid even mentioning C ;-) > If on the other hand your requirement is to specify the precision your > algorithm requires, you really do need > > type My_Float_Type is digits 7; > > and if it turns out that that needs 8 bytes (ie double), so be it. Amen! ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: type declaration and storage requirements 2002-06-04 13:04 ` Martin Dowie @ 2002-06-06 8:06 ` Simon Wright 0 siblings, 0 replies; 15+ messages in thread From: Simon Wright @ 2002-06-06 8:06 UTC (permalink / raw) "Martin Dowie" <martin.dowie@nospam.baesystems.com> writes: > or use Interfaces.C.C_Float and Interfaces.C.Double to be sure to > match C, or Interfaces.Integer_16, Interfaces.Integer_32 to avoid > even mentioning C ;-) I was going to mention that but the last 2 are integer types which doesn't match the OP's reference to "digits"! ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: type declaration and storage requirements 2002-06-02 21:21 type declaration and storage requirements Russ ` (2 preceding siblings ...) 2002-06-04 10:35 ` Simon Wright @ 2002-06-11 7:18 ` David Thompson 3 siblings, 0 replies; 15+ messages in thread From: David Thompson @ 2002-06-11 7:18 UTC (permalink / raw) Russ <18k11tm001@sneakemail.com> wrote : > Ada allows me to specify the number of digits and the range of a > floating-point type, or the delta and range of a fixed-point type. > This gives more control than, say, C/C++, which only allows me to > specify single or double precision. ... C and C++ don't have fixed-point at all, although in C++ you could cobble up a perhaps-templated class (= ADT) that does a tolerable approximation except for literals. For floating-point, there's a more-or-less workaround: #include <float.h> ... #if FLT_DIG >= 11 /* single is good enough */ typedef float mytype; #elif DBL_DIG >= 11 /* single isn't but double is */ typedef double mytype; #elif LDBL_DIG >= 11 /* not double but 'extended' */ typedef long double mytype; #else #error We lose, no suitable floating type #endif In C++, you can also use std::numeric_traits<>, but only at 'compile time' not in the preprocessor. Which Ada-trained folks may prefer anyway <G> except that it can't alter a function 'signature' i.e. the choice of dummy/formal/parameter types. And of course neither C nor C++ has user-set ranges (or subtypes) distinct from the underlying/base type's range, though again in C++ you could write a class to do it, but only at runtime cost, since the uneuphoniously-named 'non-type template parameters' can't be floating-point. Well, unless you (can) inline everything and the compiler can determine/prove no aliasing, I think that works but I'd have to try it out to be certain. (Aside: 'C/C++' is even more flamebaitful in comp.lang.c then 'ADA' is here. C is _not_ strictly a subset of C++, though it is _close_ by any reasonable measure.) -- - David.Thompson 1 now at worldnet.att.net ^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2002-06-11 7:18 UTC | newest] Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2002-06-02 21:21 type declaration and storage requirements Russ 2002-06-02 23:54 ` martin.m.dowie 2002-06-03 0:40 ` Dale Stanbrough 2002-06-03 11:10 ` martin.m.dowie 2002-06-04 2:40 ` Dale Stanbrough 2002-06-03 6:58 ` Russ 2002-06-03 7:57 ` AG 2002-06-03 11:19 ` martin.m.dowie 2002-06-03 12:40 ` Larry Kilgallen 2002-06-03 13:12 ` Gautier 2002-06-03 2:26 ` Jeffrey Carter 2002-06-04 10:35 ` Simon Wright 2002-06-04 13:04 ` Martin Dowie 2002-06-06 8:06 ` Simon Wright 2002-06-11 7:18 ` David Thompson
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox