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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,8b9403e256f252f5 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1995-03-18 06:15:22 PST Newsgroups: comp.lang.ada Path: bga.com!news.sprintlink.net!howland.reston.ans.net!gatech!news-feed-1.peachnet.edu!insosf1.infonet.net!newshost.marcam.com!uunet!world!news.bu.edu!inmet!henning!stt From: stt@henning.camb.inmet.com (Tucker Taft) Subject: Re: Float to Fixed conversions Message-ID: Sender: news@inmet.camb.inmet.com Organization: Intermetrics, Inc. X-Newsreader: TIN [version 1.1 PL8] References: Date: Sat, 18 Mar 1995 13:01:42 GMT Date: 1995-03-18T13:01:42+00:00 List-Id: Wayne Magor (wemagor@fmsa.cca.rockwell.com) wrote: : Is it legal for the program below to print 0.0? The reason I question it : is because it is DEC's Vax Ada that returns 0.0, but their Alpha Ada : returns 1.0. The 'Machine_Rounds is FALSE for Vax and TRUE for Alpha, : but a compiler on a Sun machine has 'Machine_Rounds to be FALSE and yet : still returns 1.0. Conversions between (ordinary) fixed and float can either truncate or round. The 'Machine_Rounds attribute of the *target* type "should" tell you which one happens, but that attribute is mostly oriented toward operations within a type, not conversions between types. Have you checked the 'Machine_Rounds attribute of type Fix? (By the way, in Ada 95, conversion to *decimal* fixed point requires truncation, unless you use the 'Round attribute function.) : Is there a way to adjust for these differences or is there just a bug in : the Vax Ada compiler? Is the conversion different if it is exactly half : way between the fixed point model numbers? Being exactly half way is not a special case for conversions to real type. On the other hand, when converting from real to integer, rounding is required and in Ada 95, if exactly halfway between two integers, the result has to be rounded away from zero (Ada 83 allows either direction in this case). See RM95 4.6(29-33) for the official rules, plus G.2.3(24). : procedure Fixed_Pt is : type Fixed is delta 1.0 range -10.0 .. 10.0; : Fix : Fixed; : Flt : Float := 0.999; : begin : Fix := Fixed(Flt); -- should Fix alway be set to 1.0? : end Fixed_Pt; -Tucker Taft stt@inmet.com Intermetrics, Inc.