From unknown Sat Aug 16 11:11:45 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#11310 <11310@debbugs.gnu.org> To: bug#11310 <11310@debbugs.gnu.org> Subject: Status: wrong conversions of ieee754 from/to foreign endianness Reply-To: bug#11310 <11310@debbugs.gnu.org> Date: Sat, 16 Aug 2025 18:11:45 +0000 retitle 11310 wrong conversions of ieee754 from/to foreign endianness reassign 11310 guile submitter 11310 Klaus Stehle severity 11310 normal thanks From debbugs-submit-bounces@debbugs.gnu.org Sun Apr 22 12:45:50 2012 Received: (at submit) by debbugs.gnu.org; 22 Apr 2012 16:45:50 +0000 Received: from localhost ([127.0.0.1]:47082 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SLzv3-00057Y-AT for submit@debbugs.gnu.org; Sun, 22 Apr 2012 12:45:49 -0400 Received: from eggs.gnu.org ([208.118.235.92]:40262) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SLzuy-00057I-Pn for submit@debbugs.gnu.org; Sun, 22 Apr 2012 12:45:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SLzuH-0002Pi-Fc for submit@debbugs.gnu.org; Sun, 22 Apr 2012 12:45:02 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.2 Received: from lists.gnu.org ([208.118.235.17]:35804) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SLzuH-0002PQ-CN for submit@debbugs.gnu.org; Sun, 22 Apr 2012 12:45:01 -0400 Received: from eggs.gnu.org ([208.118.235.92]:37295) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SLzuF-000572-Md for bug-guile@gnu.org; Sun, 22 Apr 2012 12:45:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SLzuD-0002Me-OZ for bug-guile@gnu.org; Sun, 22 Apr 2012 12:44:59 -0400 Received: from mx08.uni-tuebingen.de ([134.2.3.6]:44983) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SLzuD-0002E2-EI for bug-guile@gnu.org; Sun, 22 Apr 2012 12:44:57 -0400 Received: from commlink.zdv.uni-tuebingen.de (commlink.zdv.uni-tuebingen.de [134.2.2.101]) by mx08.uni-tuebingen.de (8.13.6/8.13.6) with ESMTP id q3MGo00b021360 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Sun, 22 Apr 2012 18:50:04 +0200 Date: Sun, 22 Apr 2012 18:44:44 +0200 (CEST) From: Klaus Stehle X-X-Sender: knaks01@commlink.zdv.uni-tuebingen.de To: bug-guile@gnu.org Subject: wrong conversions of ieee754 from/to foreign endianness Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-AntiVirus-Spam-Check: clean (checked by Avira MailGate: version: 3.2.1.23; spam filter version: 3.2.0/2.3; host: mx08) X-AntiVirus: checked by Avira MailGate (version: 3.2.1.23; AVE: 8.2.5.34; VDF: 7.11.10.215; host: mx08); id=14679-xUXnB0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 208.118.235.17 X-Spam-Score: -6.9 (------) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -6.9 (------) Hi, There is a problem in bytevectors.c - conversions of float and double to the foreign endianess don't work. Here is the scheme example: --------------------------- (use-modules (rnrs bytevectors)) (define bv (make-bytevector 4)) (bytevector-ieee-single-set! bv 0 1.0 (endianness little)) (display bv) (newline) => #vu8(0 0 128 63) correct! (bytevector-ieee-single-set! bv 0 1.0 (endianness big)) (display bv) (newline) => #vu8(254 0 0 0) oops! The results come from a little-endian machine and therefore the big-endian result is wrong. We expect #vu8(63 128 0 0). In bytevectors.c there is the following code: #ifdef WORDS_BIGENDIAN /* Assuming little endian for both byte and word order. */ target->little_endian.negative = src.big_endian.negative; target->little_endian.exponent = src.big_endian.exponent; target->little_endian.mantissa = src.big_endian.mantissa; #else target->big_endian.negative = src.little_endian.negative; target->big_endian.exponent = src.little_endian.exponent; target->big_endian.mantissa = src.little_endian.mantissa; #endif Using the 'FOREIGN' structure of the scm_ieee754_float union does NOT work, because in this case the structure assumes the wrong *BIT* order. example in C shows better (to run on a little endian machine): -------------------------------------------------------------- union scm_ieee754_float target; target.f = 0.0; target.litte_endian.negative = 1; => 00 00 00 80 correct! target.f = 0.0; target.big_endian.negative = 1; => 01 00 00 00 oops! Maybe this effect depends on the machine and the compiler. I am using an amd64 with gcc. The bug should be easy to fix, instead of using the ieee754 unions and their weird structures, exchanging whole bytes should suffice and this probably may be faster. Thanks Klaus From debbugs-submit-bounces@debbugs.gnu.org Sun Apr 22 14:45:42 2012 Received: (at 11310-done) by debbugs.gnu.org; 22 Apr 2012 18:45:42 +0000 Received: from localhost ([127.0.0.1]:47191 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SM1n2-0000Bf-KD for submit@debbugs.gnu.org; Sun, 22 Apr 2012 14:45:42 -0400 Received: from xanadu.aquilenet.fr ([88.191.123.111]:34883) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SM1n0-0000BM-M2 for 11310-done@debbugs.gnu.org; Sun, 22 Apr 2012 14:45:39 -0400 Received: from localhost (xanadu.aquilenet.fr [127.0.0.1]) by xanadu.aquilenet.fr (Postfix) with ESMTP id 37CF68936; Sun, 22 Apr 2012 20:44:56 +0200 (CEST) Received: from xanadu.aquilenet.fr ([127.0.0.1]) by localhost (xanadu.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id VbhSYMKM8eUc; Sun, 22 Apr 2012 20:44:56 +0200 (CEST) Received: from pluto (reverse-83.fdn.fr [80.67.176.83]) by xanadu.aquilenet.fr (Postfix) with ESMTPSA id A51078694; Sun, 22 Apr 2012 20:44:55 +0200 (CEST) From: ludo@gnu.org (Ludovic =?iso-8859-1?Q?Court=E8s?=) To: Klaus Stehle Subject: Re: bug#11310: wrong conversions of ieee754 from/to foreign endianness References: X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: 4 =?iso-8859-1?Q?Flor=E9al?= an 220 de la =?iso-8859-1?Q?R=E9volution?= X-PGP-Key-ID: 0xEA52ECF4 X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 83C4 F8E5 10A3 3B4C 5BEA D15D 77DD 95E2 EA52 ECF4 X-OS: x86_64-unknown-linux-gnu Date: Sun, 22 Apr 2012 20:44:54 +0200 In-Reply-To: (Klaus Stehle's message of "Sun, 22 Apr 2012 18:44:44 +0200 (CEST)") Message-ID: <87fwbvppw9.fsf@gnu.org> User-Agent: Gnus/5.110018 (No Gnus v0.18) Emacs/24.0.93 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -1.2 (-) X-Debbugs-Envelope-To: 11310-done Cc: 11310-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -1.2 (-) Hi Klaus, Thanks for the report! Fixed in 398446c7428b3d98d168fcc3ff170829d3e09f9a, and double-checked on HPPA. Ludo=E2=80=99. From unknown Sat Aug 16 11:11:45 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Mon, 21 May 2012 11:24:03 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator