comp.lang.ada
 help / color / mirror / Atom feed
* Float to String
@ 2004-11-08 17:06 Pascal Obry
  2004-11-08 18:29 ` Jean-Pierre Rosen
                   ` (8 more replies)
  0 siblings, 9 replies; 48+ messages in thread
From: Pascal Obry @ 2004-11-08 17:06 UTC (permalink / raw)



I was wondering if there is a way to save a float into a string and read it
back without loosing precision ?

I tried something like:

   F_Str : String (1 .. Float'Base'Digits);

   Float_Text_IO.Put (F_Str, My_Float, Aft => Float'Base'Digits);

But this is not enough... Ideas ?

Thanks,
Pascal.

-- 

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|              http://www.obry.org
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595



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

* Re: Float to String
  2004-11-08 17:06 Float to String Pascal Obry
@ 2004-11-08 18:29 ` Jean-Pierre Rosen
  2004-11-08 19:03 ` Jeffrey Carter
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 48+ messages in thread
From: Jean-Pierre Rosen @ 2004-11-08 18:29 UTC (permalink / raw)


Pascal Obry a écrit :

> I was wondering if there is a way to save a float into a string and read it
> back without loosing precision ?
> 
> I tried something like:
> 
>    F_Str : String (1 .. Float'Base'Digits);
> 
>    Float_Text_IO.Put (F_Str, My_Float, Aft => Float'Base'Digits);
> 
Of course, the catch is in "without loosing precision".

This should be possible if you write it in base 2. Note that Get will 
accept a binary floating point number, but you have to write you own Put.

-- 
---------------------------------------------------------
            J-P. Rosen (rosen@adalog.fr)
Visit Adalog's web site at http://www.adalog.fr



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

* Re: Float to String
  2004-11-08 17:06 Float to String Pascal Obry
  2004-11-08 18:29 ` Jean-Pierre Rosen
@ 2004-11-08 19:03 ` Jeffrey Carter
  2004-11-08 20:13 ` David C. Hoos
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 48+ messages in thread
From: Jeffrey Carter @ 2004-11-08 19:03 UTC (permalink / raw)


Pascal Obry wrote:

> I was wondering if there is a way to save a float into a string and
> read it back without loosing precision ?
> 
> I tried something like:
> 
> F_Str : String (1 .. Float'Base'Digits);
> 
> Float_Text_IO.Put (F_Str, My_Float, Aft => Float'Base'Digits);
> 
> But this is not enough... Ideas ?

GNAT's Float_IO uses "String (1 .. 3 * Field'Last + 2)".

You could combine that with "Aft => Field'Last, Exp => Field'Last" and 
see if that helps.

-- 
Jeff Carter
"My mind is a raging torrent, flooded with rivulets of
thought, cascading into a waterfall of creative alternatives."
Blazing Saddles
89




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

* Re: Float to String
  2004-11-08 17:06 Float to String Pascal Obry
  2004-11-08 18:29 ` Jean-Pierre Rosen
  2004-11-08 19:03 ` Jeffrey Carter
@ 2004-11-08 20:13 ` David C. Hoos
  2004-11-08 20:18 ` David C. Hoos
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 48+ messages in thread
From: David C. Hoos @ 2004-11-08 20:13 UTC (permalink / raw)
  To: Pascal Obry; +Cc: comp.lang.ada@ada.eu.org

This is closely-related to a problem I encountered something over
ten years ago.

The problem in that case was that values stored in an Oracle database
when later extracted sometimes differed in the lsb.

What makes the problem similar is that Oracle required the data to be
stored in decimal format.  The problem with that is that decimal numbers
are not, in general, exactly represent in binary.  E.g. the decimal
number 0.1 is a non-terminating binary number.

The good news is that since binary numbers in a machine per force have
a finite length, they can all be exactly represent as decimal numbers.
The bad news about this is that the Text_IO.Float_IO package
implementations I have seen are not capable of outputting those exact
representations, and we, therefore, were obliged to implement our
own, in order to satisfy the requirements of our customer to have
equivalence down to the last bit.

For binary numbers having n bits following the binary point, n digits
are required following the decimal point to exactly represent the
fractional part of the value. Such exact representations will always
terminate with the digit "5."

For binary numbers having n bits preceding the binary point, the
number of decimal digits required to exactly represent the whole-
number part of the value is (n log2 (10)) + 1.

I hope this helps.

----- Original Message ----- 
From: "Pascal Obry" <pascal@obry.net>
Newsgroups: comp.lang.ada
To: <comp.lang.ada@ada-france.org>
Sent: Monday, November 08, 2004 11:06 AM
Subject: Float to String


>
> I was wondering if there is a way to save a float into a string and read
it
> back without loosing precision ?
>
> I tried something like:
>
>    F_Str : String (1 .. Float'Base'Digits);
>
>    Float_Text_IO.Put (F_Str, My_Float, Aft => Float'Base'Digits);
>
> But this is not enough... Ideas ?
>
> Thanks,
> Pascal.
>
> -- 
>
> --|------------------------------------------------------
> --| Pascal Obry                           Team-Ada Member
> --| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
> --|------------------------------------------------------
> --|              http://www.obry.org
> --| "The best way to travel is by means of imagination"
> --|
> --| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada-france.org
> http://www.ada-france.org/mailman/listinfo/comp.lang.ada
>




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

* Re: Float to String
  2004-11-08 17:06 Float to String Pascal Obry
                   ` (2 preceding siblings ...)
  2004-11-08 20:13 ` David C. Hoos
@ 2004-11-08 20:18 ` David C. Hoos
  2004-11-09  0:40   ` John B. Matthews
  2004-11-08 21:29 ` Nick Roberts
                   ` (4 subsequent siblings)
  8 siblings, 1 reply; 48+ messages in thread
From: David C. Hoos @ 2004-11-08 20:18 UTC (permalink / raw)
  To: Pascal Obry; +Cc: comp.lang.ada@ada.eu.org

The previous message had a spelling error which was helpfully
inserted by the Micro$oft spell-checker.  The word "representable"
was "corrected" to "represent."

This is closely-related to a problem I encountered something over
ten years ago.

The problem in that case was that values stored in an Oracle database
when later extracted sometimes differed in the lsb.

What makes the problem similar is that Oracle required the data to be
stored in decimal format.  The problem with that is that decimal numbers
are not, in general, exactly representable in binary.  E.g. the decimal
number 0.1 is a non-terminating binary number.

The good news is that since binary numbers in a machine per force have
a finite length, they can all be exactly represent as decimal numbers.
The bad news about this is that the Text_IO.Float_IO package
implementations I have seen are not capable of outputting those exact
representations, and we, therefore, were obliged to implement our
own, in order to satisfy the requirements of our customer to have
equivalence down to the last bit.

For binary numbers having n bits following the binary point, n digits
are required following the decimal point to exactly represent the
fractional part of the value. Such exact representations will always
terminate with the digit "5."

For binary numbers having n bits preceding the binary point, the
number of decimal digits required to exactly represent the whole-
number part of the value is (n log2 (10)) + 1.

I hope this helps.

----- Original Message ----- 
From: "Pascal Obry" <pascal@obry.net>
Newsgroups: comp.lang.ada
To: <comp.lang.ada@ada-france.org>
Sent: Monday, November 08, 2004 11:06 AM
Subject: Float to String


>
> I was wondering if there is a way to save a float into a string and read
it
> back without loosing precision ?
>
> I tried something like:
>
>    F_Str : String (1 .. Float'Base'Digits);
>
>    Float_Text_IO.Put (F_Str, My_Float, Aft => Float'Base'Digits);
>
> But this is not enough... Ideas ?
>
> Thanks,
> Pascal.
>
> -- 
>
> --|------------------------------------------------------
> --| Pascal Obry                           Team-Ada Member
> --| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
> --|------------------------------------------------------
> --|              http://www.obry.org
> --| "The best way to travel is by means of imagination"
> --|
> --| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada-france.org
> http://www.ada-france.org/mailman/listinfo/comp.lang.ada
>




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

* Re: Float to String
  2004-11-08 17:06 Float to String Pascal Obry
                   ` (3 preceding siblings ...)
  2004-11-08 20:18 ` David C. Hoos
@ 2004-11-08 21:29 ` Nick Roberts
  2004-11-09 17:58   ` Peter Hermann
  2004-11-09  8:39 ` Dmitry A. Kazakov
                   ` (3 subsequent siblings)
  8 siblings, 1 reply; 48+ messages in thread
From: Nick Roberts @ 2004-11-08 21:29 UTC (permalink / raw)


Pascal Obry wrote:

> I was wondering if there is a way to save a float into a string and read it
> back without loosing precision ?
> 
> I tried something like:
> 
>    F_Str : String (1 .. Float'Base'Digits);
> 
>    Float_Text_IO.Put (F_Str, My_Float, Aft => Float'Base'Digits);
> 
> But this is not enough... Ideas ?

If it is not necessary for the string to be human interpretable, you could
take the approach: use streaming to convert the floating point value into
a Storage_Element_Array; write out the array as a sequence of hexadecimal
values into the string. Obviously you do the reverse to convert back to
floating point values.

-- 
Nick Roberts



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

* Re: Float to String
  2004-11-08 20:18 ` David C. Hoos
@ 2004-11-09  0:40   ` John B. Matthews
  2004-11-09  5:24     ` David C. Hoos, Sr.
  0 siblings, 1 reply; 48+ messages in thread
From: John B. Matthews @ 2004-11-09  0:40 UTC (permalink / raw)


In article 
<mailman.85.1099945145.10401.comp.lang.ada@ada-france.org>,
 "David C. Hoos" <david.c.hoos.sr@ada95.com> wrote:

[...]
> The problem in that case was that values stored in an Oracle database
> when later extracted sometimes differed in the lsb.
> 
> What makes the problem similar is that Oracle required the data to be
> stored in decimal format.  The problem with that is that decimal numbers
> are not, in general, exactly representable in binary.  E.g. the decimal
> number 0.1 is a non-terminating binary number.

Indeed. To guarantee portability among the 90-odd Oracle platforms, 
they typically store numeric data using binary coded decimal (BCD) 
with exponent. This neatly avoids the problem of binary-decimal 
conversion.

Might the data type Interfaces.COBOL.Packed_Decimal (or something 
similar) be a useful intermediate storage format?

-- 
John
----
jmatthews at wright dot edu
www dot wright dot edu/~john.matthews/



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

* Re: Float to String
  2004-11-09  0:40   ` John B. Matthews
@ 2004-11-09  5:24     ` David C. Hoos, Sr.
  0 siblings, 0 replies; 48+ messages in thread
From: David C. Hoos, Sr. @ 2004-11-09  5:24 UTC (permalink / raw)
  To: John B. Matthews; +Cc: comp.lang.ada

To the contrary, my friend.

One still must convert the floating-point binary number to decimal.
Binary-coded-decimal simply means that the decimal digits are
encoded with four bits each, but the decimal digits must be
computed just the same.

Furthermore, if the binary value is not converted to decimal with
the number of digits I specified earlier, precision is lost when
converting the decimal value back to binary for use in computation.

----- Original Message ----- 
From: "John B. Matthews" <nospam@nospam.com>
Newsgroups: comp.lang.ada
To: <comp.lang.ada@ada-france.org>
Sent: November 08, 2004 6:40 PM
Subject: Re: Float to String


> In article 
> <mailman.85.1099945145.10401.comp.lang.ada@ada-france.org>,
> "David C. Hoos" <david.c.hoos.sr@ada95.com> wrote:
> 
> [...]
>> The problem in that case was that values stored in an Oracle database
>> when later extracted sometimes differed in the lsb.
>> 
>> What makes the problem similar is that Oracle required the data to be
>> stored in decimal format.  The problem with that is that decimal numbers
>> are not, in general, exactly representable in binary.  E.g. the decimal
>> number 0.1 is a non-terminating binary number.
> 
> Indeed. To guarantee portability among the 90-odd Oracle platforms, 
> they typically store numeric data using binary coded decimal (BCD) 
> with exponent. This neatly avoids the problem of binary-decimal 
> conversion.
> 
> Might the data type Interfaces.COBOL.Packed_Decimal (or something 
> similar) be a useful intermediate storage format?
> 
> -- 
> John
> ----
> jmatthews at wright dot edu
> www dot wright dot edu/~john.matthews/
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada-france.org
> http://www.ada-france.org/mailman/listinfo/comp.lang.ada
> 
>



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

* Re: Float to String
  2004-11-08 17:06 Float to String Pascal Obry
                   ` (4 preceding siblings ...)
  2004-11-08 21:29 ` Nick Roberts
@ 2004-11-09  8:39 ` Dmitry A. Kazakov
  2004-11-09 18:17   ` Pascal Obry
  2004-11-10  5:05 ` Steve
                   ` (2 subsequent siblings)
  8 siblings, 1 reply; 48+ messages in thread
From: Dmitry A. Kazakov @ 2004-11-09  8:39 UTC (permalink / raw)


On 08 Nov 2004 18:06:04 +0100, Pascal Obry wrote:

> I was wondering if there is a way to save a float into a string and read it
> back without loosing precision ?
> 
> I tried something like:
> 
>    F_Str : String (1 .. Float'Base'Digits);
> 
>    Float_Text_IO.Put (F_Str, My_Float, Aft => Float'Base'Digits);
> 
> But this is not enough... Ideas ?

There is no any portable way to do so. Floating-point numbers are intended
to be imprecise. Normally the application domain should determine the
required accuracy. It is definitely possible to maintain that accuracy
during I/O conversions. What is impossible and meaningless, is to try to
define the *application-specific* accuracy as "the ultimate accuracy of
Float on this concrete machine for this concrete compiler". Another
question is asymptotic behavior of repeated forth and back conversions. I
would not expect that its error is unbounded, however ARM is silent about
that.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



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

* Re: Float to String
  2004-11-08 21:29 ` Nick Roberts
@ 2004-11-09 17:58   ` Peter Hermann
  2004-11-10  9:38     ` Peter Hermann
  0 siblings, 1 reply; 48+ messages in thread
From: Peter Hermann @ 2004-11-09 17:58 UTC (permalink / raw)


Nick Roberts <nick.roberts@acm.org> wrote:
> If it is not necessary for the string to be human interpretable, you could
> take the approach: use streaming to convert the floating point value into
> a Storage_Element_Array; write out the array as a sequence of hexadecimal
> values into the string. Obviously you do the reverse to convert back to
> floating point values.

this is not portable concerning different floating representations.
(and I guess this was the original requirement)

Jean-Pierre Rosen's recommendation:
>This should be possible if you write it in base 2. Note that Get will
>accept a binary floating point number, but you have to write you own
>Put.

suggests for improvement for Ada2005:
add a formal parameter "base" for real types to subroutine put.

-- 
--Peter Hermann(49)0711-685-3611 fax3758 ica2ph@csv.ica.uni-stuttgart.de
--Pfaffenwaldring 27 Raum 114, D-70569 Stuttgart Uni Computeranwendungen
--http://www.csv.ica.uni-stuttgart.de/homes/ph/
--Team Ada: "C'mon people let the world begin" (Paul McCartney)



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

* Re: Float to String
  2004-11-09  8:39 ` Dmitry A. Kazakov
@ 2004-11-09 18:17   ` Pascal Obry
  2004-11-10  8:53     ` Dmitry A. Kazakov
  0 siblings, 1 reply; 48+ messages in thread
From: Pascal Obry @ 2004-11-09 18:17 UTC (permalink / raw)



"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:

> There is no any portable way to do so. 

Well if we could read/write a float in base 2 it would work I think. So it
seems there is a way, but it seems quite a bit of work...

Pascal.

-- 

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|              http://www.obry.org
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595



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

* Re: Float to String
  2004-11-08 17:06 Float to String Pascal Obry
                   ` (5 preceding siblings ...)
  2004-11-09  8:39 ` Dmitry A. Kazakov
@ 2004-11-10  5:05 ` Steve
  2004-11-10 15:37   ` Pascal Obry
  2004-11-13 16:37 ` Ginduskina
  2004-11-13 16:39 ` Ginduskina
  8 siblings, 1 reply; 48+ messages in thread
From: Steve @ 2004-11-10  5:05 UTC (permalink / raw)


Cross platform?  Or just getting from point A to point B on the same
architecture?

Steve
(The Duck)

"Pascal Obry" <pascal@obry.net> wrote in message
news:uekj4l18j.fsf@obry.net...
>
> I was wondering if there is a way to save a float into a string and read
it
> back without loosing precision ?
>
> I tried something like:
>
>    F_Str : String (1 .. Float'Base'Digits);
>
>    Float_Text_IO.Put (F_Str, My_Float, Aft => Float'Base'Digits);
>
> But this is not enough... Ideas ?
>
> Thanks,
> Pascal.
>
> -- 
>
> --|------------------------------------------------------
> --| Pascal Obry                           Team-Ada Member
> --| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
> --|------------------------------------------------------
> --|              http://www.obry.org
> --| "The best way to travel is by means of imagination"
> --|
> --| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595





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

* Re: Float to String
  2004-11-09 18:17   ` Pascal Obry
@ 2004-11-10  8:53     ` Dmitry A. Kazakov
  2004-11-10 11:15       ` Samuel Tardieu
  0 siblings, 1 reply; 48+ messages in thread
From: Dmitry A. Kazakov @ 2004-11-10  8:53 UTC (permalink / raw)


On 09 Nov 2004 19:17:42 +0100, Pascal Obry wrote:

> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:
> 
>> There is no any portable way to do so. 
> 
> Well if we could read/write a float in base 2 it would work I think.

TοΏ½Machine_Radix is not necessarily 2. So abstractedly, 2 is not any better
than 10, 60 or whatsoever. Though in most cases it would do the trick.

> So it seems there is a way, but it seems quite a bit of work...

If you mean a machine-specific representation like

X -> <T'Machine_Radix>#<T'Fraction (X)>#E<T'Exponent (X)>

then I think it shouldn't be very difficult. If there are integers of
mantissa length, then one could directly convert T'Compose (T'Fraction (X),
T'Machine_Mantissa) to that integer. If they are shorter, then one could
use S'Compose and S'Truncate to extract mantissa digits. These operations
should be exact.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



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

* Re: Float to String
  2004-11-09 17:58   ` Peter Hermann
@ 2004-11-10  9:38     ` Peter Hermann
  2004-11-10 12:12       ` Larry Kilgallen
  0 siblings, 1 reply; 48+ messages in thread
From: Peter Hermann @ 2004-11-10  9:38 UTC (permalink / raw)



addition:

Peter Hermann <ica2ph@sinus.csv.ica.uni-stuttgart.de> wrote:
> Nick Roberts <nick.roberts@acm.org> wrote:
> > If it is not necessary for the string to be human interpretable, you could
> > take the approach: use streaming to convert the floating point value into
> > a Storage_Element_Array; write out the array as a sequence of hexadecimal
> > values into the string. Obviously you do the reverse to convert back to
> > floating point values.
> 
> this is not portable concerning different floating representations.
> (and I guess this was the original requirement[intent])

"portable" is (my) synonym of "cross platform", of course.

> Jean-Pierre Rosen's recommendation:
> >This should be possible if you write it in base 2. Note that Get will
> >accept a binary floating point number, but you have to write you own
> >Put.
> 
> suggests for improvement for Ada2005:
> add a formal parameter "base" for real types to subroutine put.

with
http://www.ada-auth.org/cgi-bin/cvsweb.cgi/AIs/AC-00070.TXT?rev=1.1
in mind, one could xfer not only in base 16 but up to base 36.
The corresponding subroutine put then should care for trailing
zeroes, when the printed radix mantissa exceeds the internal rep.

-- 
--Peter Hermann(49)0711-685-3611 fax3758 ica2ph@csv.ica.uni-stuttgart.de
--Pfaffenwaldring 27 Raum 114, D-70569 Stuttgart Uni Computeranwendungen
--http://www.csv.ica.uni-stuttgart.de/homes/ph/
--Team Ada: "C'mon people let the world begin" (Paul McCartney)



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

* Re: Float to String
  2004-11-10  8:53     ` Dmitry A. Kazakov
@ 2004-11-10 11:15       ` Samuel Tardieu
  2004-11-10 14:35         ` Dmitry A. Kazakov
                           ` (2 more replies)
  0 siblings, 3 replies; 48+ messages in thread
From: Samuel Tardieu @ 2004-11-10 11:15 UTC (permalink / raw)


>>>>> "Dmitry" == Dmitry A Kazakov <mailbox@dmitry-kazakov.de> writes:

Dmitry> TοΏ½Machine_Radix is not necessarily 2. So abstractedly, 2 is
Dmitry> not any better than 10, 60 or whatsoever. Though in most cases
Dmitry> it would do the trick.

Even using T'Machine_Radix doesn't give you a guarantee that you will
be able to read the value back on another machine with a different
'Machine_Radix.

Each time I read a thread like that, I remember why I really don't
like floating point values :)

  Sam
-- 
Samuel Tardieu -- sam@rfc1149.net -- http://www.rfc1149.net/sam



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

* Re: Float to String
  2004-11-10  9:38     ` Peter Hermann
@ 2004-11-10 12:12       ` Larry Kilgallen
  0 siblings, 0 replies; 48+ messages in thread
From: Larry Kilgallen @ 2004-11-10 12:12 UTC (permalink / raw)


In article <cmsnjf$gs9$1@news.BelWue.DE>, Peter Hermann <ica2ph@sinus.csv.ica.uni-stuttgart.de> writes:

> "portable" is (my) synonym of "cross platform", of course.

Some would take it to also include cross-compiler.

Does your definition include all validated Ada implementations,
or just certain platforms ?



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

* Re: Float to String
  2004-11-10 11:15       ` Samuel Tardieu
@ 2004-11-10 14:35         ` Dmitry A. Kazakov
  2004-11-10 15:00         ` Peter Hermann
  2004-11-10 15:35         ` Marius Amado Alves
  2 siblings, 0 replies; 48+ messages in thread
From: Dmitry A. Kazakov @ 2004-11-10 14:35 UTC (permalink / raw)


On 10 Nov 2004 12:15:04 +0100, Samuel Tardieu wrote:

>>>>>> "Dmitry" == Dmitry A Kazakov <mailbox@dmitry-kazakov.de> writes:
> 
> Dmitry> TοΏ½Machine_Radix is not necessarily 2. So abstractedly, 2 is
> Dmitry> not any better than 10, 60 or whatsoever. Though in most cases
> Dmitry> it would do the trick.
> 
> Even using T'Machine_Radix doesn't give you a guarantee that you will
> be able to read the value back on another machine with a different
> 'Machine_Radix.
> 
> Each time I read a thread like that, I remember why I really don't
> like floating point values :)

It is rather people who are trying to use floating point numbers for things
better be implemented in other numeric model. We should not blame floating
point numbers for that. (:-)) I had funny talks with non-Ada folks,
wondering why Ada has so many different types of numbers. Because we need
all of them!

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



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

* Re: Float to String
  2004-11-10 11:15       ` Samuel Tardieu
  2004-11-10 14:35         ` Dmitry A. Kazakov
@ 2004-11-10 15:00         ` Peter Hermann
  2004-11-10 15:35         ` Marius Amado Alves
  2 siblings, 0 replies; 48+ messages in thread
From: Peter Hermann @ 2004-11-10 15:00 UTC (permalink / raw)


Samuel Tardieu <sam@rfc1149.net> wrote:
> Even using T'Machine_Radix doesn't give you a guarantee that you will
> be able to read the value back on another machine with a different
> 'Machine_Radix.

agree.

different radices                 (Radieschen in German language :-)
where the bases are not products of each other
(e.g. like 2 and 16)
lead to irreversibility due to the non-infinity of the mantissa size.

-- 
--Peter Hermann(49)0711-685-3611 fax3758 ica2ph@csv.ica.uni-stuttgart.de
--Pfaffenwaldring 27 Raum 114, D-70569 Stuttgart Uni Computeranwendungen
--http://www.csv.ica.uni-stuttgart.de/homes/ph/
--Team Ada: "C'mon people let the world begin" (Paul McCartney)



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

* Re: Float to String
  2004-11-10 11:15       ` Samuel Tardieu
  2004-11-10 14:35         ` Dmitry A. Kazakov
  2004-11-10 15:00         ` Peter Hermann
@ 2004-11-10 15:35         ` Marius Amado Alves
  2004-11-10 16:35           ` Dmitry A. Kazakov
  2 siblings, 1 reply; 48+ messages in thread
From: Marius Amado Alves @ 2004-11-10 15:35 UTC (permalink / raw)
  To: comp.lang.ada

Samuel Tardieu wrote:
> Each time I read a thread like that, I remember why I really don't
> like floating point values :)

Curiuously enough, I am working on adding real types to Mneson, and 
currently I have only decimal fixed point types:

"Real values are represented by decimal fixed point types Giganano, 
Megapico, Teramicro. The name of each type indicates its range and 
precision, e.g. Giganano values range from -1G to 1G with a precision of 1n.

Not published yet. Comments welcome. The types are constrained by Ada 
(or GNAT) limit of 18 digits, and the available size is 64 bits which is 
consistent with that. This experiment made me realise that 64 bits is 
tight for any sort of universal real type implemented as fixed point. So 
I created three types, not one. And I'll leave it like this until 
evidence that float or binary is needed. Comments welcome. Mneson is a 
database system.




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

* Re: Float to String
  2004-11-10  5:05 ` Steve
@ 2004-11-10 15:37   ` Pascal Obry
  2004-11-10 16:29     ` Alex R. Mosteo
  2004-11-11  3:33     ` Steve
  0 siblings, 2 replies; 48+ messages in thread
From: Pascal Obry @ 2004-11-10 15:37 UTC (permalink / raw)



"Steve" <nospam_steved94@comcast.net> writes:

> Cross platform?  Or just getting from point A to point B on the same
> architecture?

I basically need to output an XML file with float values. These values are
cosine proximities between documents. I want to be able to read this XML file
in any computers.

Pascal.

-- 

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|              http://www.obry.org
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595



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

* Re: Float to String
  2004-11-10 15:37   ` Pascal Obry
@ 2004-11-10 16:29     ` Alex R. Mosteo
  2004-11-10 16:48       ` Pascal Obry
  2004-11-11  3:33     ` Steve
  1 sibling, 1 reply; 48+ messages in thread
From: Alex R. Mosteo @ 2004-11-10 16:29 UTC (permalink / raw)


Pascal Obry wrote:
> "Steve" <nospam_steved94@comcast.net> writes:
> 
> 
>>Cross platform?  Or just getting from point A to point B on the same
>>architecture?
> 
> 
> I basically need to output an XML file with float values. These values are
> cosine proximities between documents. I want to be able to read this XML file
> in any computers.

After all the discussion from the other people I feel really ignorant, 
but I would simply do

Float'Image (Float_Value)

and

Float'Value (String_Holding_The_Previous)

Feel free to flame it down to ashes ;)

Though the RM3.5(33) is in this case of undoubtable interest. If that's 
not enough precision for you, then the rest of comments are of obvious 
relevance.



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

* Re: Float to String
  2004-11-10 15:35         ` Marius Amado Alves
@ 2004-11-10 16:35           ` Dmitry A. Kazakov
  2004-11-10 17:28             ` Marius Amado Alves
  0 siblings, 1 reply; 48+ messages in thread
From: Dmitry A. Kazakov @ 2004-11-10 16:35 UTC (permalink / raw)


On Wed, 10 Nov 2004 15:35:30 +0000, Marius Amado Alves wrote:

> Samuel Tardieu wrote:
>> Each time I read a thread like that, I remember why I really don't
>> like floating point values :)
> 
> Curiuously enough, I am working on adding real types to Mneson, and 
> currently I have only decimal fixed point types:
> 
> "Real values are represented by decimal fixed point types Giganano, 
> Megapico, Teramicro. The name of each type indicates its range and 
> precision, e.g. Giganano values range from -1G to 1G with a precision of 1n.

The first question: what makes you believe that zero should be always
included? It might be needed if unary minus is required to be closed. See
the point? The numeric model is driven by the operations applied, their
accuracy and requirement to be closed on the domain set. But there is no
good reason why 0-x as an operation should be any better than, say, 1/x.
The latter, BTW would lead you directly to floating point representations.
If we consider other various operations we will come to interval
arithmetic, for which the very idea of a singular value (and so "precision
of a value") becomes meaningless.

So the second question: do you have have ADT in your database?

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



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

* Re: Float to String
  2004-11-10 16:29     ` Alex R. Mosteo
@ 2004-11-10 16:48       ` Pascal Obry
  2004-11-10 18:02         ` Marius Amado Alves
  0 siblings, 1 reply; 48+ messages in thread
From: Pascal Obry @ 2004-11-10 16:48 UTC (permalink / raw)



"Alex R. Mosteo" <devnull@mailinator.com> writes:

> After all the discussion from the other people I feel really ignorant, but I
> would simply do
> 
> Float'Image (Float_Value)
> 
> and
> 
> Float'Value (String_Holding_The_Previous)

That's the problem, you loose quite a bit of precision with these convertions.

Pascal.

-- 

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|              http://www.obry.org
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595



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

* Re: Float to String
  2004-11-10 16:35           ` Dmitry A. Kazakov
@ 2004-11-10 17:28             ` Marius Amado Alves
  2004-11-11 15:25               ` Dmitry A. Kazakov
  0 siblings, 1 reply; 48+ messages in thread
From: Marius Amado Alves @ 2004-11-10 17:28 UTC (permalink / raw)
  To: comp.lang.ada

> The first question: what makes you believe that zero should be always
> included? It might be needed if unary minus is required to be closed. See
> the point? The numeric model is driven by the operations applied, their
> accuracy and requirement to be closed on the domain set. But there is no
> good reason why 0-x as an operation should be any better than, say, 1/x.
> The latter, BTW would lead you directly to floating point representations.
> If we consider other various operations we will come to interval
> arithmetic, for which the very idea of a singular value (and so "precision
> of a value") becomes meaningless.

Ok, you're right. And implementing an order relation (required by the 
design of Mneson) with the three fixed point types I found myself 
replicating a floating point device so I'm reverting to a floating point 
type as the 'universal' real type!

> So the second question: do you have have ADT in your database?

In one word, no. In more words: Mneson supports ADT through its graph 
data model. Arbitrarily complex data structures are represented by 
graphs. Vertices are either basic values (integer, real, string) or 
valueless. Links are directed and untyped (unlabelled) at the base 
level. Support to represent complex structures including typed links 
exist. ADTs can be build on top of this level. Correspondence with Ada 
types, however, is supposed to occur more at the base level. I'm using 
Ada as a systems programming language only. Of course the ADTs of the 
system itself are represented in Ada. And these and others can be linked 
with Mneson graphs. I'm working on it now.

Unless you were asking about the ADTs that represent Mneson. In that 
case yes, of course they exist. For example a working graph is 
represented by an instantiation of this package:

    generic
       with function To_Vertex (Value : String) return Vertex is <>;
       with function To_Vertex (Value : Integer_64) return Vertex is <>;
       with function Valueless_Vertex
         (Number : Serial_Number) return Vertex is <>;
       with function New_Serial_Number return Serial_Number is <>;
       with function New_Vertex return Vertex is <>;
       with function Value (X : Vertex) return Integer_64 is <>;
       with function Value (X : Vertex) return String is <>;
       with function Length (X : Vertex) return Natural is <>;
       with function Slice
         (X : Vertex; Low : Positive; High : Natural) return String is <>;
       with procedure Connect (Source, Target : Vertex) is <>;
       with procedure Disconnect (Source, Target : Vertex) is <>;
       with procedure Disconnect_From_Targets (Source : Vertex) is <>;
       with procedure Disconnect_From_Sources (Target : Vertex) is <>;
       with procedure Disconnect (X : Vertex) is <>;
       with procedure Reconnect
         (Source, Target, New_Target : Vertex) is <>;
       with procedure Inv_Reconnect
         (Target, Source, New_Source : Vertex) is <>;
       with function Connected
         (Source, Target : Vertex) return Boolean is <>;
       with function Connected (Source : Vertex) return Boolean is <>;
       with function Inv_Connected (Target : Vertex) return Boolean is <>;
       with procedure For_Each_Target
         (Source : Vertex; Process : Process_Vertex) is <>;
       with procedure For_Each_Source
         (Target : Vertex; Process : Process_Vertex) is <>;
       with procedure For_Each_Link (Process : Process_Link) is <>;
       with procedure For_Each_Common_Target
         (Source_1, Source_2 : Vertex; Process : Process_Vertex) is <>;
       with function Is_Integer_64 (X : Vertex) return Boolean is <>;
       with function Is_String (X : Vertex) return Boolean is <>;
       with function Is_Valueless (X : Vertex) return Boolean is <>;
       with function Img (X : Vertex) return String is <>;
       with function Val (Img : String) return Vertex is <>;
    package Work is end;






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

* Re: Float to String
  2004-11-10 16:48       ` Pascal Obry
@ 2004-11-10 18:02         ` Marius Amado Alves
  2004-11-10 19:40           ` Jeffrey Carter
  0 siblings, 1 reply; 48+ messages in thread
From: Marius Amado Alves @ 2004-11-10 18:02 UTC (permalink / raw)
  To: comp.lang.ada

>>Float'Image (Float_Value)
>>and
>>Float'Value (String_Holding_The_Previous)
> 
> That's the problem, you loose quite a bit of precision with these convertions.

I just came across an example:

I have 64 bits available, so I define a 15 digits float

    type Float_64 is
       digits 15
       range -16#0.FFFF_FFFF_FFFF_F8#E+256
          ..  16#0.FFFF_FFFF_FFFF_F8#E+256;
    for Float_64'Size use 64;

Now I want to know the range in decimal (because the users will be 
inputing in decimal). I use 'Image on 'First and 'Last:

    First :-1.79769313486232E+308
    Last  : 1.79769313486232E+308

Now I rewrite the type definition to make it selfdocumenting:

    type Float_64 is
       digits 15
       range -1.79769313486232E+308
          ..  1.79769313486232E+308;
    for Float_64'Size use 64;

But now GNAT complaints that the size is too small, minimum allowed is 96!

Decrementing the last digit

       range -1.79769313486231E+308
          ..  1.79769313486231E+308;

makes it pass.

The culprit is probably the fact that approximations are in the 
direction away from zero.

And GNAT says 96 bits (and not 65) probably because of alignment 
requirements.

Anyway, just an illustration of how reconversions between systems (hexa 
and decimal) can be disruptive.




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

* Re: Float to String
  2004-11-10 18:02         ` Marius Amado Alves
@ 2004-11-10 19:40           ` Jeffrey Carter
  2004-11-10 21:04             ` Marius Amado Alves
  0 siblings, 1 reply; 48+ messages in thread
From: Jeffrey Carter @ 2004-11-10 19:40 UTC (permalink / raw)


Marius Amado Alves wrote:

> I have 64 bits available, so I define a 15 digits float
> 
>    type Float_64 is
>       digits 15
>       range -16#0.FFFF_FFFF_FFFF_F8#E+256
>          ..  16#0.FFFF_FFFF_FFFF_F8#E+256;
>    for Float_64'Size use 64;

Why not just

type Float_64 is digits 15;

? Or

type Biggest_Float is digits System.Max_Digits;

?

-- 
Jeff Carter
"When danger reared its ugly head, he bravely
turned his tail and fled."
Monty Python and the Holy Grail
60




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

* Re: Float to String
  2004-11-10 19:40           ` Jeffrey Carter
@ 2004-11-10 21:04             ` Marius Amado Alves
  0 siblings, 0 replies; 48+ messages in thread
From: Marius Amado Alves @ 2004-11-10 21:04 UTC (permalink / raw)
  To: comp.lang.ada

>> I have 64 bits available, so I define a 15 digits float
>>
>>    type Float_64 is
>>       digits 15
>>       range -16#0.FFFF_FFFF_FFFF_F8#E+256
>>          ..  16#0.FFFF_FFFF_FFFF_F8#E+256;
>>    for Float_64'Size use 64;
> 
> 
> Why not just
> 
> type Float_64 is digits 15;

Yes, but I want to document the range so why not rigth there?

> ? Or
> 
> type Biggest_Float is digits System.Max_Digits;

No, I want 64 bits exactly.

Thanks.




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

* Re: Float to String
  2004-11-10 15:37   ` Pascal Obry
  2004-11-10 16:29     ` Alex R. Mosteo
@ 2004-11-11  3:33     ` Steve
  2004-11-11  7:51       ` tmoran
  2004-11-11 12:30       ` Pascal Obry
  1 sibling, 2 replies; 48+ messages in thread
From: Steve @ 2004-11-11  3:33 UTC (permalink / raw)


I see two obvious choices, both of which are reasonably simple, neither of
which is exact:

1) Write the value as a string representing a floating point value with as
many significant digits as possible.  Use an Ada.Text_Io to convert the
value to a string, trim the string and add it to the XML text.

2) Write the value as an integer value.  Since you are dealing with cosines,
the range of values are between -1.0 and 1.0.  These could be mapped between
the integer values of 0 to 2^32-1, (or -2^31 to 2^31-1, take your pick).
This would give you a precision of 1/(2^32), which may be sufficient for
your application.  You may be able to handle this directly by defining a
fixed point type in Ada.

I hope this helps,
Steve
(The Duck)


"Pascal Obry" <pascal@obry.net> wrote in message
news:u654dlnq8.fsf@obry.net...
>
> "Steve" <nospam_steved94@comcast.net> writes:
>
> > Cross platform?  Or just getting from point A to point B on the same
> > architecture?
>
> I basically need to output an XML file with float values. These values are
> cosine proximities between documents. I want to be able to read this XML
file
> in any computers.
>
> Pascal.
>
> -- 
>
> --|------------------------------------------------------
> --| Pascal Obry                           Team-Ada Member
> --| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
> --|------------------------------------------------------
> --|              http://www.obry.org
> --| "The best way to travel is by means of imagination"
> --|
> --| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595





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

* Re: Float to String
  2004-11-11  3:33     ` Steve
@ 2004-11-11  7:51       ` tmoran
  2004-11-11 12:32         ` Pascal Obry
  2004-11-11 12:30       ` Pascal Obry
  1 sibling, 1 reply; 48+ messages in thread
From: tmoran @ 2004-11-11  7:51 UTC (permalink / raw)


>> I basically need to output an XML file with float values. These values are
>> cosine proximities between documents. I want to be able to read this XML
>
>1) Write the value as a string representing a floating point value with as
>many significant digits as possible.  Use an Ada.Text_Io to convert the
  The cosine here is presumably a large integer divided by the square root
of the product of two large integers.  How about just writing the three
integers, so the external representation is completely accurate.  Then let
the reader calculate the square root and division, thus generating as
accurate a float as it possibly can, given its hardware.



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

* Re: Float to String
  2004-11-11  3:33     ` Steve
  2004-11-11  7:51       ` tmoran
@ 2004-11-11 12:30       ` Pascal Obry
  1 sibling, 0 replies; 48+ messages in thread
From: Pascal Obry @ 2004-11-11 12:30 UTC (permalink / raw)



"Steve" <nospam_steved94@comcast.net> writes:

> 1) Write the value as a string representing a floating point value with as
> many significant digits as possible.  Use an Ada.Text_Io to convert the
> value to a string, trim the string and add it to the XML text.

I've done that for now, but I do not like it...

> 2) Write the value as an integer value.  Since you are dealing with cosines,
> the range of values are between -1.0 and 1.0.  These could be mapped between
> the integer values of 0 to 2^32-1, (or -2^31 to 2^31-1, take your pick).
> This would give you a precision of 1/(2^32), which may be sufficient for
> your application.  You may be able to handle this directly by defining a
> fixed point type in Ada.

I'll look at this.

Thanks,
Pascal.

-- 

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|              http://www.obry.org
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595



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

* Re: Float to String
  2004-11-11  7:51       ` tmoran
@ 2004-11-11 12:32         ` Pascal Obry
  2004-11-11 15:53           ` David C. Hoos, Sr.
  0 siblings, 1 reply; 48+ messages in thread
From: Pascal Obry @ 2004-11-11 12:32 UTC (permalink / raw)



tmoran@acm.org writes:

>   The cosine here is presumably a large integer divided by the square root
> of the product of two large integers.  How about just writing the three
> integers, so the external representation is completely accurate.  Then let
> the reader calculate the square root and division, thus generating as
> accurate a float as it possibly can, given its hardware.

Hum, I don't think this is an option for me with the current design.

Pascal.

-- 

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|              http://www.obry.org
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595



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

* Re: Float to String
  2004-11-10 17:28             ` Marius Amado Alves
@ 2004-11-11 15:25               ` Dmitry A. Kazakov
  2004-11-11 16:40                 ` Marius Amado Alves
  0 siblings, 1 reply; 48+ messages in thread
From: Dmitry A. Kazakov @ 2004-11-11 15:25 UTC (permalink / raw)


On Wed, 10 Nov 2004 17:28:55 +0000, Marius Amado Alves wrote:

>> So the second question: do you have have ADT in your database?
> 
> In one word, no. In more words: Mneson supports ADT through its graph 
> data model. Arbitrarily complex data structures are represented by 
> graphs. Vertices are either basic values (integer, real, string) or 
> valueless. Links are directed and untyped (unlabelled) at the base 
> level. Support to represent complex structures including typed links 
> exist. ADTs can be build on top of this level.

So it is kind of PL/1, pre Ada 83. You have elementary types and you can
compose structures out of them. The problem of all such approaches it that
the representation becomes fixed. When you compose a new type you define
both its representation and interface. This cannot be portable. In Ada
terms:

type My_Integer is new Integer;
   -- My_Integer is built upon Integer. This cannot be portable.
   -- Or else one should go the Integer-N way. This cure is
   -- worse than the disease.

type My_Integer is range ..;
   -- This is portable, but does not fit in your model

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



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

* Re: Float to String
  2004-11-11 12:32         ` Pascal Obry
@ 2004-11-11 15:53           ` David C. Hoos, Sr.
  2004-11-11 16:17             ` Pascal Obry
  2004-11-11 17:36             ` Jeffrey Carter
  0 siblings, 2 replies; 48+ messages in thread
From: David C. Hoos, Sr. @ 2004-11-11 15:53 UTC (permalink / raw)
  To: Pascal Obry; +Cc: comp.lang.ada

Here is a solution that preserves every bit except the last
bit in the floating point hardware.

The string representation is that of the mantissa expressed
as a decimal integer (with appropriate sign) followed by the
power of the machine radix (2 on a Windows box) by which the
integer must be multiplied to obtain the correct results.

For example, the representation of the value -0.1 (a non-
terminating number in binary is "-14757395258967641294-67".

The representation of the value 0.5 (which can be exactly
represented in binary is "9223372036854775808-64" (remember
the mantissa representation is the decimal equivalent of
a binary 1 followed by 64 zeroes).

The solution is a generic package containing two functions
(To_String and To_Value).  The generic parameter for
instantiation is the floating point type.

For IEEE 32- and 64- bit types, the representation is
exact in all of the cases I've tested.  In the case of
80-bit IEEE, there are occasional differences of one LSB.

So, here it is, along with a test program.  the test program
could be improved by generating a sequence of random numbers,
and keeping track of the worst-case relative difference.

File: precise_real_strings.ads
-----------------------------------------------
generic
   type Real is digits <>;
package Precise_Real_Strings is
   
   function To_String
     (Value : Real) return String;
   
   function To_Real
     (Representation : String) return Real;
   
   Format_Error : exception;
   
end Precise_Real_Strings;

-----------------------------------------------
   

File: precise_real_strings.adb
-----------------------------------------------
   
with Ada.Exceptions;
with Ada.Strings.Fixed;
with Ada.Strings.Maps;
with Interfaces;
package body Precise_Real_Strings is

   procedure Reset;
   pragma Import (C, Reset, "__gnat_init_float");
   --  We import the floating-point processor reset routine so that we can
   --  be sure the floating-point processor is properly set for conversion
   --  calls (see description of Reset in GNAT.Float_Control (g-flocon.ads).
   --  This is notably need on Windows, where calls to the operating system
   --  randomly reset the processor into 64-bit mode.

   -------------
   -- To_Real --
   -------------

   function To_Real
     (Representation : String)
      return Real
   is
      Separator   : Natural;
      Separators  : constant String := " +-";
      Sign_pos    : Natural;
      Exponent    : Integer;
      Mantissa    : Interfaces.Unsigned_64;
      Is_Negative : Boolean;
      procedure Raise_With_Message is
      begin
         Ada.Exceptions.Raise_Exception
           (Format_Error'Identity,
            "Invalid representation: """ & Representation & """.");
      end;
   begin
      Reset;
      Separator := Ada.Strings.Fixed.Index
        (Representation (Representation'First + 1 .. Representation'Last),
         Ada.Strings.Maps.To_Set (separators));
      if Separator = 0 then
         Raise_With_Message;
      end if;
      begin
         Exponent := Integer'Value
           (Representation (Separator .. Representation'Last));
      exception
         when others =>
            Raise_With_Message;
      end;
      Sign_pos := Ada.Strings.Fixed.Index
        (Representation (Representation'First .. Separator - 1),
         Ada.Strings.Maps.To_Set ('-'));
      Is_Negative := Sign_Pos /= 0;
      Mantissa := Interfaces.Unsigned_64'Value
        (Representation (Sign_Pos + 1 .. Separator - 1));
      declare
         Result : Real := Real'Scaling (Real (Mantissa), Exponent);
      begin
         if Sign_Pos = 0 then
            return Result;
         else
            return - Result;
         end if;
      end;
   end To_Real;

   ---------------
   -- To_String --
   ---------------

   function To_String (Value : Real) return String
   is
      Exponent : Integer;
      Mantissa : Interfaces.Unsigned_64;
      Sign     : Character;
   begin
      Reset;
      if Value < 0.0 then
         Sign := '-';
      else Sign := ' ';
      end if;
      Exponent := Real'Exponent (Value) -Real'Machine_Mantissa;
      Mantissa := Interfaces.Unsigned_64
        (Real'Scaling (abs (Value), - Exponent));
      declare
         Mantissa_String : String := Interfaces.Unsigned_64'Image (Mantissa);
      begin
         Mantissa_String (1) := Sign;
         return Mantissa_String & Integer'Image (Exponent);
      end;
   end To_String;

end Precise_Real_Strings;

-----------------------------------------------

File: test_precise_real_strings.adb
-----------------------------------------------
with Ada.Text_IO;
with Precise_Real_Strings;
procedure Test_Precise_Real_Strings
is
   package Llf is new Precise_Real_Strings (Long_Long_Float);
   package Lf is new Precise_Real_Strings (Long_Float);
   package F is new Precise_Real_Strings (Float);
begin
   declare
      Representation : String := Llf.To_String (-0.1);
   begin
      Ada.Text_IO.Put_Line (Representation);
      Ada.Text_IO.Put_Line
        (Long_Long_Float'Image
         (Llf.To_Real (Representation)));
      Representation (1) := '+';
      Ada.Text_IO.Put_Line
        (Long_Long_Float'Image
         (Llf.To_Real (Representation)));
      Representation (1) := ' ';
      Ada.Text_IO.Put_Line
        (Long_Long_Float'Image
         (Llf.To_Real (Representation)));
      Ada.Text_IO.Put_Line
        ("Relative difference:" & Long_Long_Float'Image
        ((Llf.To_Real (Representation) - 0.1)/ 0.1));
      Ada.Text_IO.Put_Line
        ("Precise match? " &
         Boolean'Image (Llf.To_Real (Representation) = 0.1));
   end;
   Ada.Text_IO.New_Line;
   declare
      Representation : String := Lf.To_String (-0.1);
   begin
      Ada.Text_IO.Put_Line (Representation);
      Ada.Text_IO.Put_Line
        (Long_Float'Image
         (Lf.To_Real (Representation)));
      Representation (1) := '+';
      Ada.Text_IO.Put_Line
        (Long_Float'Image
         (Lf.To_Real (Representation)));
      Representation (1) := ' ';
      Ada.Text_IO.Put_Line
        (Long_Float'Image
         (Lf.To_Real (Representation)));
      Ada.Text_IO.Put_Line
        ("Relative difference:" & Long_Float'Image
        ((Lf.To_Real (Representation) - 0.1)/ 0.1));
      Ada.Text_IO.Put_Line
        ("Precise match? " &
         Boolean'Image (Lf.To_Real (Representation) = 0.1));
   end;
   Ada.Text_IO.New_Line;
   declare
      Representation : String := F.To_String (-0.1);
   begin
      Ada.Text_IO.Put_Line (Representation);
      Ada.Text_IO.Put_Line
        (Float'Image
         (F.To_Real (Representation)));
      Representation (1) := '+';
     Ada.Text_IO.Put_Line
        (Float'Image
         (F.To_Real (Representation)));
      Representation (1) := ' ';
      Ada.Text_IO.Put_Line
        (Float'Image
         (F.To_Real (Representation)));
      Ada.Text_IO.Put_Line
        ("Relative difference:" & Float'Image
        ((F.To_Real (Representation) - 0.1)/ 0.1));
      Ada.Text_IO.Put_Line
        ("Precise match? " &
         Boolean'Image (F.To_Real (Representation) = 0.1));
   end;
   Ada.Text_IO.New_Line;
end;

-----------------------------------------------

Here are the results of ruinning the test program:

-14757395258967641294-67
-1.00000000000000000E-01
 1.00000000000000000E-01
 1.00000000000000000E-01
Relative difference: 6.77626357803440271E-20
Precise match? FALSE

-7205759403792794-56
-1.00000000000000E-01
 1.00000000000000E-01
 1.00000000000000E-01
Relative difference: 0.00000000000000E+00
Precise match? TRUE

-13421773-27
-1.00000E-01
 1.00000E-01
 1.00000E-01
Relative difference: 0.00000E+00
Precise match? TRUE

----- Original Message ----- 
From: "Pascal Obry" <pascal@obry.org>
Newsgroups: comp.lang.ada
To: <comp.lang.ada@ada-france.org>
Sent: November 11, 2004 6:32 AM
Subject: Re: Float to String


> 
> tmoran@acm.org writes:
> 
>>   The cosine here is presumably a large integer divided by the square root
>> of the product of two large integers.  How about just writing the three
>> integers, so the external representation is completely accurate.  Then let
>> the reader calculate the square root and division, thus generating as
>> accurate a float as it possibly can, given its hardware.
> 
> Hum, I don't think this is an option for me with the current design.
> 
> Pascal.
> 
> -- 
> 
> --|------------------------------------------------------
> --| Pascal Obry                           Team-Ada Member
> --| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
> --|------------------------------------------------------
> --|              http://www.obry.org
> --| "The best way to travel is by means of imagination"
> --|
> --| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada-france.org
> http://www.ada-france.org/mailman/listinfo/comp.lang.ada
> 
>



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

* Re: Float to String
  2004-11-11 15:53           ` David C. Hoos, Sr.
@ 2004-11-11 16:17             ` Pascal Obry
  2004-11-11 17:36             ` Jeffrey Carter
  1 sibling, 0 replies; 48+ messages in thread
From: Pascal Obry @ 2004-11-11 16:17 UTC (permalink / raw)



"David C. Hoos, Sr." <david.c.hoos.sr@ada95.com> writes:

> Here is a solution that preserves every bit except the last
> bit in the floating point hardware.

Thanks David. I'll have a look at this.

Pascal.

-- 

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|              http://www.obry.org
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595



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

* Re: Float to String
  2004-11-11 15:25               ` Dmitry A. Kazakov
@ 2004-11-11 16:40                 ` Marius Amado Alves
  2004-11-11 18:31                   ` Dmitry A. Kazakov
  0 siblings, 1 reply; 48+ messages in thread
From: Marius Amado Alves @ 2004-11-11 16:40 UTC (permalink / raw)
  To: comp.lang.ada

> So it is kind of PL/1, pre Ada 83. You have elementary types and you can
> compose structures out of them. The problem of all such approaches it that
> the representation becomes fixed....

Not a problem here. Mneson is not for system programming. Mneson gives 
you a semantic data model. It is a database system. Data independence 
implies lost of representation control.

> type My_Integer is new Integer;
>    -- My_Integer is built upon Integer. This cannot be portable.
>    -- Or else one should go the Integer-N way. This cure is
>    -- worse than the disease.
> 
> type My_Integer is range ..;
>    -- This is portable, but does not fit in your model

Yes it fits, because Mneson basic types are designed big enough [1]. If 
you have Ada integers you want to store in Mneson you just convert to 
Integer_64.

    X : Vertex := To_Vertex (Integer_64 (Your_Integer));

And (at the base level) Mneson does not check the range, but you will 
get that when you convert back to Your_Integer.

    Your_Integer := My_Integer (Integer_64'(Value (X)));
________
[1] Well, "big enough" is currently 64 bits. There will be a 128-bit 
version eventually.




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

* Re: Float to String
  2004-11-11 15:53           ` David C. Hoos, Sr.
  2004-11-11 16:17             ` Pascal Obry
@ 2004-11-11 17:36             ` Jeffrey Carter
  2004-11-12  0:01               ` David C. Hoos, Sr.
  1 sibling, 1 reply; 48+ messages in thread
From: Jeffrey Carter @ 2004-11-11 17:36 UTC (permalink / raw)


David C. Hoos, Sr. wrote:

>   function To_Real
>     (Representation : String)
>      return Real
>   is
>      Separator   : Natural;
>      Separators  : constant String := " +-";

...

>      Separator := Ada.Strings.Fixed.Index
>        (Representation (Representation'First + 1 .. Representation'Last),
>         Ada.Strings.Maps.To_Set (separators));
>      if Separator = 0 then
>         Raise_With_Message;
>      end if;

...

>   function To_String (Value : Real) return String

...

>         return Mantissa_String & Integer'Image (Exponent);

Is this an error? To_Real wants a sign on the exponent ('+' or '-') but 
Integer'Image does not add '+' to non-negative values.

-- 
Jeff Carter
"If a sperm is wasted, God gets quite irate."
Monty Python's the Meaning of Life
56




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

* Re: Float to String
  2004-11-11 16:40                 ` Marius Amado Alves
@ 2004-11-11 18:31                   ` Dmitry A. Kazakov
  2004-11-11 22:27                     ` Marius Amado Alves
  0 siblings, 1 reply; 48+ messages in thread
From: Dmitry A. Kazakov @ 2004-11-11 18:31 UTC (permalink / raw)


On Thu, 11 Nov 2004 16:40:30 +0000, Marius Amado Alves wrote:

>> So it is kind of PL/1, pre Ada 83. You have elementary types and you can
>> compose structures out of them. The problem of all such approaches it that
>> the representation becomes fixed....
> 
> Not a problem here. Mneson is not for system programming. Mneson gives 
> you a semantic data model. It is a database system. Data independence 
> implies lost of representation control.

Isn't it controversial? To me independency means not to control the
representation, which might only illusory anyway, but to control the
interface. You define your requirements and it is up to the system to
figure out how to fulfill them. This is the way Ada 83 tried to deal with
numeric types.

>> type My_Integer is new Integer;
>>    -- My_Integer is built upon Integer. This cannot be portable.
>>    -- Or else one should go the Integer-N way. This cure is
>>    -- worse than the disease.
>> 
>> type My_Integer is range ..;
>>    -- This is portable, but does not fit in your model
> 
> Yes it fits, because Mneson basic types are designed big enough [1]. If 
> you have Ada integers you want to store in Mneson you just convert to 
> Integer_64.
> 
>     X : Vertex := To_Vertex (Integer_64 (Your_Integer));
> 
> And (at the base level) Mneson does not check the range, but you will 
> get that when you convert back to Your_Integer.
> 
>     Your_Integer := My_Integer (Integer_64'(Value (X)));
> ________
> [1] Well, "big enough" is currently 64 bits. There will be a 128-bit 
> version eventually.

And then 256-bit, where is any end? What you are trying to do is to define
a god-integer type to satisfy all possible requirements. That is
impossible. You can make it 1024-bit, but then it will be unsuitable for
pixels of an image. What about a database scalable from an embedded
microcontroller to a super cluster?

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



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

* Re: Float to String
  2004-11-11 18:31                   ` Dmitry A. Kazakov
@ 2004-11-11 22:27                     ` Marius Amado Alves
  2004-11-12 12:19                       ` Dmitry A. Kazakov
  0 siblings, 1 reply; 48+ messages in thread
From: Marius Amado Alves @ 2004-11-11 22:27 UTC (permalink / raw)
  To: comp.lang.ada

[... 64, 128....]
> And then 256-bit, where is any end? What you are trying to do is to define
> a god-integer type to satisfy all possible requirements. That is
> impossible.

Yes, but I just want "big enough" for common values in databases. The 
current triad of types Integer_64, Float_64, String is enough.

> You can make it 1024-bit, but then it will be unsuitable for
> pixels of an image.

Pixels would be stored in a String. Because you can convert 
(uncheckedly) any contiguous value to String. Like the "blob" type of 
Oracle et al. (Remember Mneson is NOT an *Ada* object database. It is a 
database system that happens to be implemented in Ada.)

> What about a database scalable from an embedded
> microcontroller to a super cluster?

This is another issue. Mneson can run on any system that is a target of 
an Ada compiler. I believe this includes some of those, no?





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

* Re: Float to String
  2004-11-11 17:36             ` Jeffrey Carter
@ 2004-11-12  0:01               ` David C. Hoos, Sr.
  2004-11-12  0:30                 ` Jeffrey Carter
  0 siblings, 1 reply; 48+ messages in thread
From: David C. Hoos, Sr. @ 2004-11-12  0:01 UTC (permalink / raw)
  To: Jeffrey Carter; +Cc: comp.lang.ada

No, it is not an error.  Note that the Separators
string contains three characters, blank, plus, and minus.

So, To_Real wants one of those three characters to
separate the mantissa and the exponent.

----- Original Message ----- 
From: "Jeffrey Carter" <spam@spam.com>
Newsgroups: comp.lang.ada
To: <comp.lang.ada@ada-france.org>
Sent: November 11, 2004 11:36 AM
Subject: Re: Float to String


> David C. Hoos, Sr. wrote:
> 
>>   function To_Real
>>     (Representation : String)
>>      return Real
>>   is
>>      Separator   : Natural;
>>      Separators  : constant String := " +-";
> 
> ...
> 
>>      Separator := Ada.Strings.Fixed.Index
>>        (Representation (Representation'First + 1 .. Representation'Last),
>>         Ada.Strings.Maps.To_Set (separators));
>>      if Separator = 0 then
>>         Raise_With_Message;
>>      end if;
> 
> ...
> 
>>   function To_String (Value : Real) return String
> 
> ...
> 
>>         return Mantissa_String & Integer'Image (Exponent);
> 
> Is this an error? To_Real wants a sign on the exponent ('+' or '-') but 
> Integer'Image does not add '+' to non-negative values.
> 
> -- 
> Jeff Carter
> "If a sperm is wasted, God gets quite irate."
> Monty Python's the Meaning of Life
> 56
> 
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada-france.org
> http://www.ada-france.org/mailman/listinfo/comp.lang.ada
> 
>



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

* Re: Float to String
  2004-11-12  0:01               ` David C. Hoos, Sr.
@ 2004-11-12  0:30                 ` Jeffrey Carter
  0 siblings, 0 replies; 48+ messages in thread
From: Jeffrey Carter @ 2004-11-12  0:30 UTC (permalink / raw)


David C. Hoos, Sr. wrote:
> No, it is not an error.  Note that the Separators
> string contains three characters, blank, plus, and minus.
> 
> So, To_Real wants one of those three characters to
> separate the mantissa and the exponent.

So it does. Sorry. Despite looking at that at least 3 times, I managed 
to miss the space.

-- 
Jeff Carter
"No one is to stone anyone until I blow this whistle,
do you understand? Even--and I want to make this
absolutely clear--even if they do say, 'Jehova.'"
Monty Python's Life of Brian
74




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

* Re: Float to String
  2004-11-11 22:27                     ` Marius Amado Alves
@ 2004-11-12 12:19                       ` Dmitry A. Kazakov
  2004-11-12 14:55                         ` Marius Amado Alves
  0 siblings, 1 reply; 48+ messages in thread
From: Dmitry A. Kazakov @ 2004-11-12 12:19 UTC (permalink / raw)


On Thu, 11 Nov 2004 22:27:07 +0000, Marius Amado Alves wrote:

> [... 64, 128....]
>> And then 256-bit, where is any end? What you are trying to do is to define
>> a god-integer type to satisfy all possible requirements. That is
>> impossible.
> 
> Yes, but I just want "big enough" for common values in databases. The 
> current triad of types Integer_64, Float_64, String is enough.

If "big enough" should be a requirement, then what is "enough"?

>> You can make it 1024-bit, but then it will be unsuitable for
>> pixels of an image.
> 
> Pixels would be stored in a String. Because you can convert 
> (uncheckedly) any contiguous value to String. Like the "blob" type of 
> Oracle et al.

Well, this not ADT, this is not even typed. Like in FORTRAN-IV where
everything was LOGICAL*1 array...

> (Remember Mneson is NOT an *Ada* object database. It is a 
> database system that happens to be implemented in Ada.)

Here Ada is only an example of a typed language, which tried to keep type
interface and implementation separate.

>> What about a database scalable from an embedded
>> microcontroller to a super cluster?
> 
> This is another issue. Mneson can run on any system that is a target of 
> an Ada compiler. I believe this includes some of those, no?

64-bit floats and integers on a 16-bit controller?

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



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

* Re: Float to String
  2004-11-12 12:19                       ` Dmitry A. Kazakov
@ 2004-11-12 14:55                         ` Marius Amado Alves
  0 siblings, 0 replies; 48+ messages in thread
From: Marius Amado Alves @ 2004-11-12 14:55 UTC (permalink / raw)
  To: comp.lang.ada

>>>What about a database scalable from an embedded
>>>microcontroller to a super cluster?
>>
>>This is another issue. Mneson can run on any system that is a target of 
>>an Ada compiler. I believe this includes some of those, no?
> 
> 64-bit floats and integers on a 16-bit controller?

You tell me. It works on 32-bit systems namely my Pentium 3 laptop. So 
there is some emulation going on. And so at least theoretically you can 
also emulate on 16-bit. (And if not and Mneson is still wanted on some 
such system I'd be happy to produce a downgraded version :-)




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

* Re: Float to String
  2004-11-08 17:06 Float to String Pascal Obry
                   ` (6 preceding siblings ...)
  2004-11-10  5:05 ` Steve
@ 2004-11-13 16:37 ` Ginduskina
  2004-11-13 18:41   ` Björn Lundin
  2004-11-13 16:39 ` Ginduskina
  8 siblings, 1 reply; 48+ messages in thread
From: Ginduskina @ 2004-11-13 16:37 UTC (permalink / raw)


Hello. This may seem a syupid question, given the kind of replies users
have posted so far yet, but.... I can't understand how to pass from float
to string.. i don't need much precision, i just need the instruction/s i
need to use to get my string with my float number... which will have its
point numbers, and the exponent numbers

Please help!!


(Thank You)




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

* Re: Float to String
  2004-11-08 17:06 Float to String Pascal Obry
                   ` (7 preceding siblings ...)
  2004-11-13 16:37 ` Ginduskina
@ 2004-11-13 16:39 ` Ginduskina
  2004-11-13 16:49   ` Simon Wright
                     ` (2 more replies)
  8 siblings, 3 replies; 48+ messages in thread
From: Ginduskina @ 2004-11-13 16:39 UTC (permalink / raw)


Hello. This may seem a syupid question, given the kind of replies users
have posted so far yet, but.... I can't understand how to pass from float
to string.. i don't need much precision, i just need the instruction/s i
need to use to get my string with my float number... which will have its
point numbers, and the exponent numbers

Please help!!


(Thank You)




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

* Re: Float to String
  2004-11-13 16:39 ` Ginduskina
@ 2004-11-13 16:49   ` Simon Wright
  2004-11-13 16:53   ` David C. Hoos, Sr.
  2004-11-13 16:55   ` Pascal Obry
  2 siblings, 0 replies; 48+ messages in thread
From: Simon Wright @ 2004-11-13 16:49 UTC (permalink / raw)


"Ginduskina" <luminis_stella@hotmail.com> writes:

> Hello. This may seem a syupid question, given the kind of replies
> users have posted so far yet, but.... I can't understand how to pass
> from float to string.. i don't need much precision, i just need the
> instruction/s i need to use to get my string with my float
> number... which will have its point numbers, and the exponent
> numbers

Hi,

   with Ada.Text_IO; use Ada.Text_IO;
   procedure Floats is
      F : Float;
   begin

      --  from string ..
      F := Float'Value ("0.12345");

      --  to string, portably ...
      Put_Line ("F is " & Float'Image (F));

      --  to string, GNAT-only
      Put_Line ("F is " & F'Img);

   end Floats;

here, gives
  
   smaug.pushface.org[2]$ gnatmake floats
   gcc -c floats.adb
   gnatbind -x floats.ali
   gnatlink floats.ali
   smaug.pushface.org[3]$ ./floats
   F is  1.23450E-01
   F is  1.23450E-01

-- 
Simon Wright                               100% Ada, no bugs.



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

* Re: Float to String
  2004-11-13 16:39 ` Ginduskina
  2004-11-13 16:49   ` Simon Wright
@ 2004-11-13 16:53   ` David C. Hoos, Sr.
  2004-11-13 16:55   ` Pascal Obry
  2 siblings, 0 replies; 48+ messages in thread
From: David C. Hoos, Sr. @ 2004-11-13 16:53 UTC (permalink / raw)
  To: Ginduskina; +Cc: comp.lang.ada

The string is obtained from a float value by calling the image
attribute of the Float type, i.e.
Float'Image (<some float expression>)

The value represented by the string is obtained as follows
Float'Value (< some string representing a floating-point value>)

----- Original Message ----- 
From: "Ginduskina" <luminis_stella@hotmail.com>
Newsgroups: comp.lang.ada
To: <comp.lang.ada@ada-france.org>
Sent: November 13, 2004 10:39 AM
Subject: Re: Float to String


> Hello. This may seem a syupid question, given the kind of replies users
> have posted so far yet, but.... I can't understand how to pass from float
> to string.. i don't need much precision, i just need the instruction/s i
> need to use to get my string with my float number... which will have its
> point numbers, and the exponent numbers
> 
> Please help!!
> 
> 
> (Thank You)
> 
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada-france.org
> http://www.ada-france.org/mailman/listinfo/comp.lang.ada
> 
>



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

* Re: Float to String
  2004-11-13 16:39 ` Ginduskina
  2004-11-13 16:49   ` Simon Wright
  2004-11-13 16:53   ` David C. Hoos, Sr.
@ 2004-11-13 16:55   ` Pascal Obry
  2 siblings, 0 replies; 48+ messages in thread
From: Pascal Obry @ 2004-11-13 16:55 UTC (permalink / raw)



"Ginduskina" <luminis_stella@hotmail.com> writes:

> Hello. This may seem a syupid question, given the kind of replies users
> have posted so far yet, but.... I can't understand how to pass from float
> to string.. i don't need much precision, 

The way to do that is quite easy:

   Str : constant String := Float'Image (3.4);

And from a String to a Float:

   F : constant Float := Float'Value (Str);

But, as discussed in this thread, you are going to loose precision.

Pascal.

-- 

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|              http://www.obry.org
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595



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

* Re: Float to String
  2004-11-13 16:37 ` Ginduskina
@ 2004-11-13 18:41   ` Björn Lundin
  0 siblings, 0 replies; 48+ messages in thread
From: Björn Lundin @ 2004-11-13 18:41 UTC (permalink / raw)
  To: comp.lang.ada

lördag 13 november 2004 17:37 skrev Ginduskina:
> Hello. This may seem a syupid question, given the kind of replies users
> have posted so far yet, but.... I can't understand how to pass from float
> to string.. i don't need much precision, i just need the instruction/s i
> need to use to get my string with my float number... which will have its
> point numbers, and the exponent numbers
>
use the attibute Image as in Float'Image. Works on most (all?) scalar and 
float types, as integer, duration, and new scalar and float types you define

with Text_Io;
procedure Float_To_String is
  A_Float : Float := 1.23456789;
  A_String : String := Float'Image(A_Float);
begin
  Text_Io.Put_Line(A_String);
end Float_To_String;


would produce


[bnl@della2 test]$ ./float_to_string
 1.23457E+00
[bnl@della2 test]$ 




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

end of thread, other threads:[~2004-11-13 18:41 UTC | newest]

Thread overview: 48+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-11-08 17:06 Float to String Pascal Obry
2004-11-08 18:29 ` Jean-Pierre Rosen
2004-11-08 19:03 ` Jeffrey Carter
2004-11-08 20:13 ` David C. Hoos
2004-11-08 20:18 ` David C. Hoos
2004-11-09  0:40   ` John B. Matthews
2004-11-09  5:24     ` David C. Hoos, Sr.
2004-11-08 21:29 ` Nick Roberts
2004-11-09 17:58   ` Peter Hermann
2004-11-10  9:38     ` Peter Hermann
2004-11-10 12:12       ` Larry Kilgallen
2004-11-09  8:39 ` Dmitry A. Kazakov
2004-11-09 18:17   ` Pascal Obry
2004-11-10  8:53     ` Dmitry A. Kazakov
2004-11-10 11:15       ` Samuel Tardieu
2004-11-10 14:35         ` Dmitry A. Kazakov
2004-11-10 15:00         ` Peter Hermann
2004-11-10 15:35         ` Marius Amado Alves
2004-11-10 16:35           ` Dmitry A. Kazakov
2004-11-10 17:28             ` Marius Amado Alves
2004-11-11 15:25               ` Dmitry A. Kazakov
2004-11-11 16:40                 ` Marius Amado Alves
2004-11-11 18:31                   ` Dmitry A. Kazakov
2004-11-11 22:27                     ` Marius Amado Alves
2004-11-12 12:19                       ` Dmitry A. Kazakov
2004-11-12 14:55                         ` Marius Amado Alves
2004-11-10  5:05 ` Steve
2004-11-10 15:37   ` Pascal Obry
2004-11-10 16:29     ` Alex R. Mosteo
2004-11-10 16:48       ` Pascal Obry
2004-11-10 18:02         ` Marius Amado Alves
2004-11-10 19:40           ` Jeffrey Carter
2004-11-10 21:04             ` Marius Amado Alves
2004-11-11  3:33     ` Steve
2004-11-11  7:51       ` tmoran
2004-11-11 12:32         ` Pascal Obry
2004-11-11 15:53           ` David C. Hoos, Sr.
2004-11-11 16:17             ` Pascal Obry
2004-11-11 17:36             ` Jeffrey Carter
2004-11-12  0:01               ` David C. Hoos, Sr.
2004-11-12  0:30                 ` Jeffrey Carter
2004-11-11 12:30       ` Pascal Obry
2004-11-13 16:37 ` Ginduskina
2004-11-13 18:41   ` Björn Lundin
2004-11-13 16:39 ` Ginduskina
2004-11-13 16:49   ` Simon Wright
2004-11-13 16:53   ` David C. Hoos, Sr.
2004-11-13 16:55   ` Pascal Obry

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