comp.lang.ada
 help / color / mirror / Atom feed
* Converting numbers to strings without Ada.Text_IO?
@ 2004-04-08 17:25 Tapio Kelloniemi
  2004-04-08 18:14 ` Martin Dowie
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Tapio Kelloniemi @ 2004-04-08 17:25 UTC (permalink / raw)


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



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2004-04-12  5:13 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2004-04-09  9:58 ` Dmitry A. Kazakov
2004-04-12  5:13 ` Richard  Riehle

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