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,a6692a7d92b3309b,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2004-04-08 10:25:43 PST Path: archiver1.google.com!news1.google.com!news.glorb.com!ecngs!feeder.ecngs.de!news.cambrium.nl!news.cambrium.nl!fi.sn.net!newsfeed2.fi.sn.net!newsfeed.bahnhof.se!feeder1.news.jippii.net!reader1.news.jippii.net!53ab2750!not-for-mail From: Tapio Kelloniemi Subject: Converting numbers to strings without Ada.Text_IO? Newsgroups: comp.lang.ada Message-ID: Date: Thu, 08 Apr 2004 17:25:43 GMT NNTP-Posting-Host: 217.30.176.187 X-Complaints-To: newsmaster@saunalahti.com X-Trace: reader1.news.jippii.net 1081445143 217.30.176.187 (Thu, 08 Apr 2004 20:25:43 EEST) NNTP-Posting-Date: Thu, 08 Apr 2004 20:25:43 EEST Organization: Saunalahti Customer Xref: archiver1.google.com comp.lang.ada:6856 Date: 2004-04-08T17:25:43+00:00 List-Id: Hi I'm writing a collection of generic packages to format numbers (similar to Ada.Text_IO.xxx_IO). The reason why I don't use the strings-versions of procedures under Ada.Text_IO are: - 'With'ing Ada.Text_IO has side-efects on some systems (eg. information about unhandled exceptions, adding blank lines to terminal at program termination...) - Ada.Text_IO has many features which I don't need. - Number formatting routines in Text_IO only accept bases in range 2 .. 16 (I know that higher bases are very seldom needed). - Formatting routines of Text_IO are procedures which prevents determining the result strings' lengths in assignment. - I want to add some features which Ada.Text_IO misses. Well, my question is: how could in convert integer and real numbers portably into strings without using Ada.Text_IO? My idea is to convert variables of generic integer and real types to some type that can represent all possible integers or reals on that system and then recursively extracting the digits by dividing by base etc. Are there some issues that I should be aware of? Attempt: type Max_Integer is new range System.Min_Int .. System.Max_Int; type Max_Real is digits System.Max_Digits; ... -- Returns the last digit of an integer number as character. -- This is not a final form, but is it correct or very inefficient? function Last_Digit (N : Number) return Character is begin if abs N >= Base then return To_Char (Last_Digit (abs (N / Base))); else return To_Char (abs N); end if; end Last_Digit; -- Tapio