public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-5428] [Ada] Ada.Numerics.Big_Numbers.Big_Reals.To_Big_Real looses precision
@ 2020-11-26  8:43 Pierre-Marie de Rodat
  0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2020-11-26  8:43 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:e3068952d7540c51764d1e4e31ef8988492064cf

commit r11-5428-ge3068952d7540c51764d1e4e31ef8988492064cf
Author: Arnaud Charlet <charlet@adacore.com>
Date:   Fri Oct 30 11:23:49 2020 -0400

    [Ada] Ada.Numerics.Big_Numbers.Big_Reals.To_Big_Real looses precision
    
    gcc/ada/
    
            * libgnat/a-nbnbre.adb (To_Big_Real): Do not loose precision.

Diff:
---
 gcc/ada/libgnat/a-nbnbre.adb | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/gcc/ada/libgnat/a-nbnbre.adb b/gcc/ada/libgnat/a-nbnbre.adb
index 8459539d212..ff5b4488381 100644
--- a/gcc/ada/libgnat/a-nbnbre.adb
+++ b/gcc/ada/libgnat/a-nbnbre.adb
@@ -32,6 +32,7 @@
 --  This is the default version of this package, based on Big_Integers only.
 
 with Ada.Strings.Text_Output.Utils;
+with System.Img_Real; use System.Img_Real;
 
 package body Ada.Numerics.Big_Numbers.Big_Reals is
 
@@ -122,8 +123,15 @@ package body Ada.Numerics.Big_Numbers.Big_Reals is
       -----------------
 
       function To_Big_Real (Arg : Num) return Valid_Big_Real is
+         S : String (1 .. Max_Real_Image_Length);
+         P : Natural := 0;
       begin
-         return From_String (Arg'Image);
+         --  Use Long_Long_Unsigned'Width - 1 digits = 20 which is sufficient
+         --  for the largest floating point format.
+
+         Set_Image_Real
+           (Long_Long_Float (Arg), S, P, Fore => 1, Aft => 20, Exp => 5);
+         return From_String (S (1 .. P));
       end To_Big_Real;
 
       -------------------


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-11-26  8:43 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-26  8:43 [gcc r11-5428] [Ada] Ada.Numerics.Big_Numbers.Big_Reals.To_Big_Real looses precision Pierre-Marie de Rodat

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).