From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by sourceware.org (Postfix) with ESMTPS id 41D6B3889E2C for ; Thu, 5 Jan 2023 14:40:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 41D6B3889E2C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-wm1-x334.google.com with SMTP id l26so26580135wme.5 for ; Thu, 05 Jan 2023 06:40:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=nxi5J3BLHE2iy3hLO7IcngAzM6Pg1xcJDF0nqZmXtWA=; b=NpDD2c9XVynp8Sl28GsGtFdlszXKcjyZdQG3u+tL6afR2AZvdrnMqS63uKYIpYIWeF lRjgOzT7cLy160JPhKLJYGsF4SfnJQxlTziCaVeayKfrCg5vYx6uLOFag6wcyIslukrT XPVVqFp0s+xDij5glLWmdwYykY4s9K8JNC0klybNkk75GEUtJ/8rkGp8VgHFqkrlAsze tVHh7UPynasKacpvWcIwDtlotOExXWbFtfdXPInhnRuV/NjWYLov4KzdSbbUNOaz/XJz ezjPuaZKTSobLYkbh+hSqneEglsBWWNFy4xtRODfoUlWbCAswWKcQZNn6mSDZiJEl8kx frJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=nxi5J3BLHE2iy3hLO7IcngAzM6Pg1xcJDF0nqZmXtWA=; b=rQBcn+zOldP8yvkSu1o+cC7lAG+Cs9EE+Ew3BQ3bszFQgrMz7Phdi/72g8bLDQQMMP 2i47N6xiGtIR+GVC3KZ4twBzVJQOvDkb7Q/D3/zqBMB0SArz0gpokluYPrJ3cT5pwKlp DxLWfjGfLuLbesJlQruIy8iwnLW3EVZ7BvvJtYs8xlk2VDmLgRzw4ejUzTst3qfBR3Mm 7g2267gUZL2lsSEv91zc2159gmYtcaHFWtEWURqCU9FDck4M8jow2ftGjMtpW9qMdhh4 0ACthriUjsjIJRDrw4hVieMYdL9yWn5nEu7Ml79jw5RluJIddEyy9DLYR2W4fZXNTbtd pBDg== X-Gm-Message-State: AFqh2korTtbWuDHW3BU1u5a4T2qOJr4MqaBO1kjC45c6/zA1AHKAm0E1 23GjKIzcvvwtY0+ibL7KhFFIqU3sAZNEmU63oTY= X-Google-Smtp-Source: AMrXdXuBiJ5oG0ekMcGCy9hroDz1cnx7zdRqkYJaHazhKcXv4ZyIj00oPtrAnT3JZZEcs60AhVUGVA== X-Received: by 2002:a05:600c:3b93:b0:3d3:43ae:4d10 with SMTP id n19-20020a05600c3b9300b003d343ae4d10mr39195342wms.11.1672929648110; Thu, 05 Jan 2023 06:40:48 -0800 (PST) Received: from poulhies-Precision-5550.lan (static-176-191-105-132.ftth.abo.bbox.fr. [176.191.105.132]) by smtp.gmail.com with ESMTPSA id n17-20020a05600c4f9100b003cffd3c3d6csm2984329wmq.12.2023.01.05.06.40.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Jan 2023 06:40:47 -0800 (PST) From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [COMMITTED] ada: Do not use decimal approximation in -gnatRj output Date: Thu, 5 Jan 2023 15:40:45 +0100 Message-Id: <20230105144045.156314-1-poulhies@adacore.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-13.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,WEIRD_QUOTING autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: From: Eric Botcazou This avoids an unnecessary loss of precision for real values. gcc/ada/ * repinfo.ads (The JSON output format): Document change. * urealp.adb (UR_Write_To_JSON): Output a fraction instead of a decimal approximation. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/repinfo.ads | 4 ++-- gcc/ada/urealp.adb | 39 +++++++++++++-------------------------- 2 files changed, 15 insertions(+), 28 deletions(-) diff --git a/gcc/ada/repinfo.ads b/gcc/ada/repinfo.ads index 64624077cec..f9200ee04e4 100644 --- a/gcc/ada/repinfo.ads +++ b/gcc/ada/repinfo.ads @@ -196,8 +196,8 @@ package Repinfo is -- "Object_Size" : numerical expression -- "Value_Size" : numerical expression -- "Component_Size" : numerical expression - -- "Range" : array of numbers - -- "Small" : number + -- "Range" : array of numerical expressions + -- "Small" : numerical expression -- "Alignment" : number -- "Convention" : string -- "Linker_Section" : string diff --git a/gcc/ada/urealp.adb b/gcc/ada/urealp.adb index 830520788d9..37bf3a7cb79 100644 --- a/gcc/ada/urealp.adb +++ b/gcc/ada/urealp.adb @@ -1518,14 +1518,11 @@ package body Urealp is -- UR_Write_To_JSON -- ---------------------- - -- We defer to the implementation of UR_Write in all cases, either directly - -- for values that are naturally written in a JSON compatible format, or by - -- first computing a decimal approximation for other values. + -- We defer to the implementation of UR_Write for values that are naturally + -- written in a JSON compatible format and write a fraction for the others. procedure UR_Write_To_JSON (Real : Ureal) is - Val : constant Ureal_Entry := Ureals.Table (Real); - Imrk : constant Uintp.Save_Mark := Mark; - Rmrk : constant Urealp.Save_Mark := Mark; + Val : constant Ureal_Entry := Ureals.Table (Real); T : Ureal; @@ -1561,31 +1558,21 @@ package body Urealp is elsif Val.Rbase = 0 and then Val.Num mod Val.Den = 0 then T := Real; - -- For other constants, compute an approximation in base 10 + -- Other non-based (rational) constants are written in num/den style else - declare - A : constant Ureal := UR_Abs (Real); - -- The absolute value - - E : constant Uint := - (if A < Ureal_1 - then UI_From_Int (3 - Decimal_Exponent_Lo (Real)) - else Uint_3); - -- The exponent for at least 3 digits after the decimal point - - Num : constant Uint := - UR_To_Uint (UR_Mul (A, UR_Exponentiate (Ureal_10, E))); - -- The numerator appropriately rounded - - begin - T := UR_From_Components (Num, E, 10, Val.Negative); - end; + Write_Str ("{ ""code"": ""/"", ""operands"": [ "); + if Val.Negative then + Write_Char ('-'); + end if; + UI_Write (Val.Num, Decimal); + Write_Str (".0, "); + UI_Write (Val.Den, Decimal); + Write_Str (".0 ] }"); + return; end if; UR_Write (T); - Release (Imrk); - Release (Rmrk); end UR_Write_To_JSON; ------------- -- 2.34.1