From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,8c0fcfc0a87e61fc X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!nx02.iad01.newshosting.com!newshosting.com!novia!news-xxxfer.readnews.com!news-out.readnews.com!postnews3.readnews.com!not-for-mail Date: Thu, 30 Sep 2010 17:21:02 -0400 From: "Peter C. Chapin" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.9) Gecko/20100915 Lightning/1.0b2 Thunderbird/3.1.4 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: simple question on long_float/short_float References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Message-ID: <4ca4fff8$0$2437$4d3efbfe@news.sover.net> Organization: SoVerNet (sover.net) NNTP-Posting-Host: e98d7a9d.news.sover.net X-Trace: DXC=;BG\I_UmkGF1H3;A[4ZP5AK6_LM2JZB_CMdY=PfmYBfO^KZ4X^8KgIH_72H[?]1\@NZNoJViSMEaK X-Complaints-To: abuse@sover.net Xref: g2news1.google.com comp.lang.ada:14340 Date: 2010-09-30T17:21:02-04:00 List-Id: On 2010-09-30 11:37, Jeffrey Carter wrote: > Are you saying that in Fortran you can only make floating-point > variables with one of two precisions? > > Is this for real? I don't know about old Fortran but in Fortran 90 and above you can specify the characteristics of your floating point type and ask the compiler to find an underlying type that works for you. Each compiler provides various "kinds" of floating point types. Depending on the underlying machine there might be several. These kinds are identified by compiler specific integer constants (kind 1, kind 2, etc). Of course referring to them that way isn't portable... my floating point type that is labeled as "kind 1" might be nothing like the floating point type you are labeling as "kind 1." To get around this you can use the intrinsic function SELECTED_REAL_KIND. It looks like this: INTEGER, PARAMETER :: my_floating_kind = SELECTED_REAL_KIND(6, 30) This asks the compiler to find a floating point type with at least 6 digits of precision and a range that covers 10**30. The resulting kind (some number like 1, 2, 3, etc) is then given the name "my_floating_kind." I declare variables like this REAL(KIND = my_floating_kind) :: x, y, z The kind value is like a type parameter. Thus REAL(KIND = 1) means you want the first kind of floating point type, REAL(KIND = 2) means you want the second kind. In the declaration above "my_floating_kind" is used meaning that you want whatever kind is necessary to get the desired precision and range. Maybe that's kind 2 on my compiler and kind 17 on yours. Fortran compilers are required (I think) to provide a double precision type but internally that type is just a particular kind (maybe kind 2?). In modern Fortran you never have to say "double precision" the term exists for compatibility and convenience. We now return to our regularly scheduled discussion of Ada. :) Peter