From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id iC7mDRDtNmQMwQAASxT56A (envelope-from ) for ; Wed, 12 Apr 2023 19:40:32 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id UD3sDRDtNmQ9IAEA9RJhRA (envelope-from ) for ; Wed, 12 Apr 2023 19:40:32 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id E828528F5E for ; Wed, 12 Apr 2023 19:40:31 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pmeRh-0004rv-Po; Wed, 12 Apr 2023 13:39:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pmeRc-0004rT-JO for guix-devel@gnu.org; Wed, 12 Apr 2023 13:39:44 -0400 Received: from hera.aquilenet.fr ([2a0c:e300::1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pmeRa-0004ou-FF for guix-devel@gnu.org; Wed, 12 Apr 2023 13:39:44 -0400 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id F0E231F32; Wed, 12 Apr 2023 19:39:37 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at hera.aquilenet.fr Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id BWSUJxdiPiV6; Wed, 12 Apr 2023 19:39:37 +0200 (CEST) Received: from jurong (unknown [IPv6:2001:861:c4:f2f0::c64]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 330BAB4D; Wed, 12 Apr 2023 19:39:37 +0200 (CEST) Date: Wed, 12 Apr 2023 19:39:35 +0200 From: Andreas Enge To: Simon Tournier Cc: guix-devel@gnu.org Subject: Re: Julia and Ocaml Message-ID: References: <87cz49glec.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <87cz49glec.fsf@gmail.com> Received-SPF: pass client-ip=2a0c:e300::1; envelope-from=andreas@enge.fr; helo=hera.aquilenet.fr X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guix-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+larch=yhetil.org@gnu.org Sender: guix-devel-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Seal: i=1; s=key1; d=yhetil.org; t=1681321232; a=rsa-sha256; cv=none; b=GquvFFKvZIAiKSusxXC4e57+0lQsKUXIpD/SW0itm3Bxx1lavZSs1Tm0khyekcCgLyxaJO 7PmTpZD+OhOTRHdn2i8SNCM5Ai1B1ycbQbS2JZ46mdeDqRA63w+EGOINiwWUGySTkVIKBc GjnT1xQHQkSglFw/onx8l7E0XLpyzK1HUNgumuzcV25TkGeR4lV8AagyVaHATtgnu7G0Zj MdhgWKdwHwqTbXqR3KTFWZ3NjvW7IAYjPlQ+v9MjlETw9sqFNWC3reuFLdfW5Ae7R7F9MG p5xmHP5Wh+p2iY5tf2fpzJx9kHyR4Og6hnIYjl921/glxxEKZP0Wv5AMJF7VWg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; spf=pass (aspmx1.migadu.com: domain of "guix-devel-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-devel-bounces+larch=yhetil.org@gnu.org"; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1681321232; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=A0+jKEf10WQFHNKgcfUaxlWjgSGd/6yZlQJX/aNZkWw=; b=eh7NlhQJrhFRav9mMwXFvWHstlT+ew4oiVUUgrYF3vgoeB+qe0FshrsKQvZyqXVPj09zbo omyDUOyGz61sobdFNoBWfNqox8Iz1mb5ChDUv1JFPe3vy6QFiFiKVm9TMlUk+yqmgJ5TUB xPXX3CMelu1BdLd7BrIlrR/X45uYF8n8vdQF9mNY0wquPeFXMh1GQg+jIGEnVKxEw/CgmP K4+kVAcGYN6+MABUWB1shMZW1EL7zkOTBcAFf7S4r4hDld0xEJVWR+CCiBM7nUPOWdwcor rHqCWxYOfdeMPatnra46n95x9u8HwYNWzFpJtyFY8c1ifIKvzH5GfRFMm/apvw== X-Migadu-Queue-Id: E828528F5E Authentication-Results: aspmx1.migadu.com; dkim=none; spf=pass (aspmx1.migadu.com: domain of "guix-devel-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-devel-bounces+larch=yhetil.org@gnu.org"; dmarc=none X-Migadu-Scanner: scn0.migadu.com X-Migadu-Spam-Score: -3.52 X-Spam-Score: -3.52 X-TUID: mcUuyc6Ow9bA TLDR: Solution for julia in the last paragraph. Am Wed, Apr 12, 2023 at 05:39:23PM +0200 schrieb Simon Tournier: > About Julia [1], it comes from the update of mpfr and I have no clue how > to fix that. Any idea? Well, mixing base 10 and base 2 calls for trouble... I will try to go through this, maybe we can get an idea of the cause. But it depends on the Julia functions parse and string, so it could mean quite some work to go through their source code. > Error in testset mpfr: > Test Failed at /tmp/guix-build-julia-1.8.3.drv-0/julia-1.8.3/test/mpfr.jl:667 > Expression: string(parse(BigFloat, "0.1")) == "0.10000002" > Evaluated: "0.1" == "0.10000002" This comes from the following code: setprecision(21) do @test string(parse(BigFloat, "0.1")) == "0.10000002" ... I assume that means that we are working with 21 bit floating point precision. 0.1 lies between 1677721*2^-24 and 1677722*2^-24, but is closer to the latter. So with rounding to nearest, I would expect the result of parse(BigFloat, "0.1")) to be 1677722*2^-24. Now one would need to know what the string function does. MPFR, for instance, has a function that either allows the user to fix the number of digits, or (by passing 0) outputs a few extra digits so that, when reading the number again into a variable of 21 bits, one is sure to recover the same number 1677722*2^-24. Of course here "0.1" would be a good output; but the semantic does not specify the output, anything sufficiently close to 0.1 would also be considered correct. Here 0.10000002*2^24 = 1677721.93554432, and it would also be read in again as 1677722*2^-24. (Otherwise said, the equivalent functions of parse and string from mpfr satisfy parse o string == id; instead of checking whether string o parse outputs a specific value, I think it would have been better to test whether parse o string o parse == parse on some values). I looked at the source code of julia, but am not sufficiently familiar with it to understand where and how parse and string are defined. I think they might use mpfr_set_str for parse and mpfr_asprintf for string. At least I see this in base/mpfr.jl: function string_mpfr(x::BigFloat, fmt::String) pc = Ref{Ptr{UInt8}}() n = ccall((:mpfr_asprintf,libmpfr), Cint, (Ptr{Ptr{UInt8}}, Ptr{UInt8}, Ref{BigFloat}...), pc, fmt, x) ... function _string(x::BigFloat, fmt::String)::String isfinite(x) || return string(Float64(x)) _prettify_bigfloat(string_mpfr(x, fmt)) end _string(x::BigFloat) = _string(x, "%Re") _string(x::BigFloat, k::Integer) = _string(x, "%.$(k)Re") The format string "%Re" means output an mpfr ("R") and use the precision convention as detailed above ("e"). I tried to mimick this with pure mpfr code; both libraries, the 4.1.0 we have in Guix master and 4.2.0, read in 0.1 as 1677722*2^-24, then output it again as 1.0000002e-01. The julia function _prettify_bigfloat from mpfr.jl probably transforms this into 0.10000002. So I have no idea why in the test apparently string(parse(BigFloat, "0.1")) yields "0.1". Oh, I do; here is a change: -_string(x::BigFloat) = _string(x, "%.Re") +_string(x::BigFloat) = _string(x, "%Re") With the . in the format string, mpfr@4.2 indeed prints out 1e-01, whereas mpfr@4.1 used to print 1.0000002e-01. (News item from MPFR: "Bug fixes: In particular, for the formatted output functions (mpfr_printf, etc.), the case where the precision consists only of a period has been fixed to be like .0 as specified in the ISO C standard, and the manual has been corrected and clarified.") This is part of a larger commit commit 1e5fdb29f8858f3244f6aff116ee12e4c8247f3a Author: Simon Byrne Date: Tue Jan 10 14:52:36 2023 -0800 update MPFR to 4.2.0 (#48165) Co-authored-by: Mosè Giordano This should be part of the upcoming 1.9.0 release of julia. You could try to apply this commit in isolation, or update to 1.8.5 and apply the commit then if it does not apply otherwise. Good luck! Andreas