From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Klaus Stehle Newsgroups: gmane.lisp.guile.bugs Subject: bug#11310: wrong conversions of ieee754 from/to foreign endianness Date: Sun, 22 Apr 2012 18:44:44 +0200 (CEST) Message-ID: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Trace: dough.gmane.org 1335113136 17872 80.91.229.3 (22 Apr 2012 16:45:36 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sun, 22 Apr 2012 16:45:36 +0000 (UTC) To: 11310@debbugs.gnu.org Original-X-From: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Sun Apr 22 18:45:33 2012 Return-path: Envelope-to: guile-bugs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1SLzum-0005n9-LY for guile-bugs@m.gmane.org; Sun, 22 Apr 2012 18:45:32 +0200 Original-Received: from localhost ([::1]:44102 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SLzul-0005Ca-SK for guile-bugs@m.gmane.org; Sun, 22 Apr 2012 12:45:31 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:37431) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SLzui-0005CJ-Ii for bug-guile@gnu.org; Sun, 22 Apr 2012 12:45:29 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SLzug-0002v6-N2 for bug-guile@gnu.org; Sun, 22 Apr 2012 12:45:28 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:46048) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SLzug-0002uk-JP for bug-guile@gnu.org; Sun, 22 Apr 2012 12:45:26 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1SLzvG-00057z-Bj for bug-guile@gnu.org; Sun, 22 Apr 2012 12:46:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Klaus Stehle Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-guile@gnu.org Resent-Date: Sun, 22 Apr 2012 16:46:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 11310 X-GNU-PR-Package: guile X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-guile@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.133511315019691 (code B ref -1); Sun, 22 Apr 2012 16:46:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 22 Apr 2012 16:45:50 +0000 Original-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 Original-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 Original-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 Original-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 Original-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 Original-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 Original-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 Original-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 X-X-Sender: knaks01@commlink.zdv.uni-tuebingen.de 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-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 140.186.70.43 X-BeenThere: bug-guile@gnu.org List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Original-Sender: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.bugs:6321 Archived-At: 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