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,509f8e43dc081fde X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news.glorb.com!npeer.de.kpn-eurorings.net!newsfeed.vmunix.org!peer-uk.news.demon.net!kibo.news.demon.net!news.demon.co.uk!demon!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: Simulation of fixed point in c WITH DIFFERENT BIT-WIDTH Date: Thu, 03 Nov 2005 06:13:19 +0000 Organization: Pushface Message-ID: References: <1130690498.388857.225170@g49g2000cwa.googlegroups.com> <1130690498.388857.225170@g49g2000cwa.googlegroups.com> NNTP-Posting-Host: pogner.demon.co.uk Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: news.demon.co.uk 1130998402 18428 62.49.19.209 (3 Nov 2005 06:13:22 GMT) X-Complaints-To: abuse@demon.net NNTP-Posting-Date: Thu, 3 Nov 2005 06:13:22 +0000 (UTC) Cancel-Lock: sha1:uhd+W5uOPVktL81xD+h2OTcowG4= User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (darwin) Xref: g2news1.google.com comp.lang.ada:6136 Date: 2005-11-03T06:13:19+00:00 List-Id: Colin Paul Gloster writes: > Mnamky did not say in > news:1130690498.388857.225170@g49g2000cwa.googlegroups.com that the > datatypes could take negative values, but anyway Gautier's > type F1 is delta 2.0**(-11) range -1.0 .. 1.0; > is a wasteful declaration which is bigger than Mnamky's "12-bit > wordlength and 11-bit fraction". > A two's complement signed 1 bit integer can have as its lowest value -1 > and as its greatest value 0. > So > type F3 is delta 2.0**(-11) range -1.0 .. 1.0 - 2.0**(-11); > type F4 is delta 2.0**(-14) range -2.0 .. 2.0 - 2.0**(-14); > are more appropiate datatypes. I'm not sure what is actually required for portability here. AARM95 3.5.9(22-24) says The base range of an ordinary fixed point type need not include the specified bounds themselves so that the range specification can be given in a natural way, such as: type Fraction is delta 2.0**(-15) range -1.0 .. 1.0; With 2's complement hardware, such a type could have a signed 16-bit representation, using 1 bit for the sign and 15 bits for fraction, resulting in a base range of -1.0 .. 1.0-2.0**(-15). With GCC 4.0.0 on Darwin, this program with Ada.Text_IO; use Ada.Text_IO; procedure Gloster is type F1 is delta 2.0**(-11) range -1.0 .. 1.0; for F1'Size use 12; type F2 is delta 2.0**(-14) range -1.0 .. 1.0; for F2'Size use 15; type F3 is delta 2.0**(-11) range -1.0 .. 1.0 - 2.0**(-11); type F4 is delta 2.0**(-14) range -2.0 .. 2.0 - 2.0**(-14); begin Put_Line ("F1's size is" & Natural'Image (F1'Size)); Put_Line ("F2's size is" & Natural'Image (F2'Size)); Put_Line ("F3's size is" & Natural'Image (F3'Size)); Put_Line ("F4's size is" & Natural'Image (F4'Size)); end Gloster; outputs $ ./gloster F1's size is 12 F2's size is 15 F3's size is 12 F4's size is 16 Commenting out the representation clauses, the output is $ ./gloster F1's size is 13 F2's size is 16 F3's size is 12 F4's size is 16 I'm not sure why F4's size is 16, though; is this a bug?