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,cc6a4bc415a41111 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.11.199 with SMTP id s7mr47551922pbb.5.1317410862421; Fri, 30 Sep 2011 12:27:42 -0700 (PDT) MIME-Version: 1.0 Path: lh7ni8498pbb.0!nntp.google.com!news1.google.com!news.glorb.com!feeder.erje.net!feeder.news-service.com!aioe.org!.POSTED!not-for-mail From: tmoran@acm.org Newsgroups: comp.lang.ada Subject: Re: fixed point vs floating point Date: Fri, 30 Sep 2011 19:26:53 +0000 (UTC) Organization: Aioe.org NNTP Server Message-ID: References: <82lit6z64n.fsf@stephe-leake.org> NNTP-Posting-Host: Lf0Nl3CcQzx+ocHx9cmuGg.user.speranza.aioe.org X-Complaints-To: abuse@aioe.org X-Notice: Filtered by postfilter v. 0.8.2 X-Newsreader: Tom's custom newsreader Xref: news1.google.com comp.lang.ada:18245 Date: 2011-09-30T19:26:53+00:00 List-Id: > The only place I have found fixed point to be useful is for time; > everything else ends up needing to be scaled, so it might as well be > floating point from the beginning. Also for matching instrument or control values, formatting output, saving memory, interfacing to C stuff, or future proofing. In embedded devices measurements usually come in implicitly scaled integers, not float, as do output control values. If Degrees is fixed point, Degrees'image is much more readable than if it's in floating point. Usually real world physical values don't need 32 or more bits of float for either their range or precision. If memory size (or IO time) is an issue, they can be stored in much smaller fixed point format. Very often values passed to C et al are scaled, eg durations are milliseconds or seconds or hundreths of seconds, represented as integers, angles are tenths of a degree integers, and so forth. Trying to do calculations remembering the proper scaling is error-prone, but the compiler will do it correctly if you use fixed point. Intensities (eg color, sound) are always fractions, but they are usually represented as if they were integers ranging from 0 .. 15, or 0 .. 255, or 0 .. 65535. Code like Is_Bright := (Color > 128); is much more tedious and error-prone to change then Is_Bright := (Color > 0.5);