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,1038abdfae2ba73 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news2.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!wns13feed!worldnet.att.net!attbi_s21.POSTED!53ab2750!not-for-mail From: "Jeffrey R. Carter" User-Agent: Thunderbird 2.0.0.17 (Windows/20080914) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Modify value - type duration References: <7ef68540-6df1-4e47-b425-ab08c03f2db9@p31g2000prf.googlegroups.com> In-Reply-To: <7ef68540-6df1-4e47-b425-ab08c03f2db9@p31g2000prf.googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: NNTP-Posting-Host: 12.201.97.213 X-Complaints-To: abuse@mchsi.com X-Trace: attbi_s21 1225925279 12.201.97.213 (Wed, 05 Nov 2008 22:47:59 GMT) NNTP-Posting-Date: Wed, 05 Nov 2008 22:47:59 GMT Organization: AT&T ASP.att.net Date: Wed, 05 Nov 2008 22:47:59 GMT Xref: g2news2.google.com comp.lang.ada:8316 Date: 2008-11-05T22:47:59+00:00 List-Id: Andreas.Schmidl@googlemail.com wrote: > function cutIt(var : duration) return duration is > > tempvar : integer; > > begin > tempvar := integer(var); > return (var - duration(tempvar)); > > end cutIt; > > But this isn't a solution. Converting to integer with integer(...) > round the value. > Example: > 12.345 ---> 12 > 12.854 ---> 13 > > Is there any other more elegant and functional solution in Ada? Back in the good old days of Ada 83, we'd subtract 0.5 from the value before converting to an integer type. Note that a Duration may contain a value that cannot be converted to Integer. These days, you can use an appropriate floating-point type and the 'Truncation attribute function to get the integer part: function Cut_It (Value : in Duration) return Duration is type Big is digits System.Max_Digits; begin -- Cut_It return Value - Duration (Big'Truncation (Big (Value) ) ); end Cut_It; -- Jeff Carter "You a big nose have it." Never Give a Sucker an Even Break 107