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=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=unavailable autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,a6692a7d92b3309b X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2004-04-08 17:08:43 PST Path: archiver1.google.com!news1.google.com!news.glorb.com!newsrout1.ntli.net!news.ntli.net!proxad.net!usenet-fr.net!enst.fr!melchior!cuivre.fr.eu.org!melchior.frmug.org!not-for-mail From: Stephen Leake Newsgroups: comp.lang.ada Subject: Re: Converting numbers to strings without Ada.Text_IO? Date: 08 Apr 2004 20:06:19 -0400 Organization: Cuivre, Argent, Or Message-ID: References: NNTP-Posting-Host: lovelace.ada-france.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: melchior.cuivre.fr.eu.org 1081469188 61756 212.85.156.195 (9 Apr 2004 00:06:28 GMT) X-Complaints-To: usenet@melchior.cuivre.fr.eu.org NNTP-Posting-Date: Fri, 9 Apr 2004 00:06:28 +0000 (UTC) To: comp.lang.ada@ada-france.org Return-Path: In-Reply-To: User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 X-Virus-Scanned: by amavisd-new-20030616-p7 (Debian) at ada-france.org X-BeenThere: comp.lang.ada@ada-france.org X-Mailman-Version: 2.1.4 Precedence: list List-Id: "Gateway to the comp.lang.ada Usenet newsgroup" List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Xref: archiver1.google.com comp.lang.ada:6871 Date: 2004-04-08T20:06:19-04:00 Tapio Kelloniemi writes: > 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: Good list; snipped for space. > Well, my question is: how could in convert integer and real numbers > portably into strings without using Ada.Text_IO? Martin Dowie suggested copying the core code from GNAT; that's a good idea. Here's code I wrote that converts modular types to hexadecimal: function SAL.Generic_Hex_Image (Item : in Number_Type) return String is Temp : Number_Type := Item; Nibble : Number_Type; Image : String (1 .. Width); begin for I in reverse Image'Range loop Nibble := Temp mod 16; Temp := Temp / 16; if Nibble > 9 then Image (I) := Character'Val (Character'Pos ('A') + Nibble - 10); else Image (I) := Character'Val (Character'Pos ('0') + Nibble); end if; end loop; return Image; end Sal.Generic_Hex_Image; > Are there some issues that I should be aware of? Lots. Go read the GNAT code. -- -- Stephe