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,XPRIO autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,55d12b9409d3b4cd,start X-Google-Attributes: gid103376,public Path: controlnews3.google.com!news1.google.com!news.glorb.com!news2.telebyte.nl!news.newsland.it!news-out.tin.it!news-in.tin.it!news.finmeccanica.it!not-for-mail From: "Davide" Newsgroups: comp.lang.ada Subject: Newbie Question: Casting Issue Date: Tue, 4 May 2004 11:22:03 +0200 Organization: Finmeccanica Message-ID: NNTP-Posting-Host: 192.168.54.114 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2600.0000 X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 Xref: controlnews3.google.com comp.lang.ada:229 Date: 2004-05-04T11:22:03+02:00 List-Id: I need your help, please, to solve a casting issue. I have an Ada operation, say FLOAT_POINT_OP, which returns a floating point type, say: FLOAT_POINT_TYPE is digits 9. The result of this operation must be assigned to a fixed point type variable, say: FIX_POINT_TYPE is delta 0.0625 range -10.0 .. 36.5. I cannot use Ada exceptions and I must ensure that the assignment will not throw a type constraint error at run-time. Then I perform this check: FLOAT_VAR >= FLOAT_POINT_TYPE(FIX_POINT_TYPE'FIRST) and FLOAT_VAR <= FLOAT_POINT_TYPE(FIX_POINT_TYPE'LAST) (where FLOAT_VAR is the floating point type result returned by FLOAT_POINT_OP) and if the check passes then I perform the "crucial" assignment: FIX_VAR := FLOAT_VAR. Do you think it works fine? Have you better solutions? My worry is about the FLOAT_POINT_TYPE(FIX_POINT_TYPE'FIRST) casting. In particular about the possibility of an introduction of additional decimal digits, after the last decimal digit of the FIX_POINT_TYPE bounds. I think that everything should work if the casting preserves at least the number of decimal digits specified for delta (in this case 4 digits, being delta = 0.0625) adding possible digits after the fourth. There is some Ada standard directive about that? Thank you.