comp.lang.ada
 help / color / mirror / Atom feed
From: Stephen Leake <stephen_leake@acm.org>
To: comp.lang.ada@ada-france.org
Subject: Re: Converting numbers to strings without Ada.Text_IO?
Date: 08 Apr 2004 20:06:19 -0400
Date: 2004-04-08T20:06:19-04:00	[thread overview]
Message-ID: <mailman.227.1081469187.327.comp.lang.ada@ada-france.org> (raw)
In-Reply-To: <rWfdc.2825$MA6.804@reader1.news.jippii.net>

Tapio Kelloniemi <spam12@thack.org> 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




  parent reply	other threads:[~2004-04-09  0:06 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-04-08 17:25 Converting numbers to strings without Ada.Text_IO? Tapio Kelloniemi
2004-04-08 18:14 ` Martin Dowie
2004-04-09  3:50   ` James Rogers
2004-04-09  6:03     ` Martin Dowie
2004-04-09 12:34       ` James Rogers
2004-04-09  0:06 ` Stephen Leake [this message]
2004-04-09  9:58 ` Dmitry A. Kazakov
2004-04-12  5:13 ` Richard  Riehle
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox