GNU bug report logs - #11310
wrong conversions of ieee754 from/to foreign endianness

Previous Next

Package: guile;

Reported by: Klaus Stehle <klaus.stehle <at> uni-tuebingen.de>

Date: Sun, 22 Apr 2012 16:46:01 UTC

Severity: normal

Done: ludo <at> gnu.org (Ludovic Courtès)

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 11310 in the body.
You can then email your comments to 11310 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-guile <at> gnu.org:
bug#11310; Package guile. (Sun, 22 Apr 2012 16:46:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Klaus Stehle <klaus.stehle <at> uni-tuebingen.de>:
New bug report received and forwarded. Copy sent to bug-guile <at> gnu.org. (Sun, 22 Apr 2012 16:46:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Klaus Stehle <klaus.stehle <at> uni-tuebingen.de>
To: bug-guile <at> gnu.org
Subject: wrong conversions of ieee754 from/to foreign endianness
Date: Sun, 22 Apr 2012 18:44:44 +0200 (CEST)
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




Reply sent to ludo <at> gnu.org (Ludovic Courtès):
You have taken responsibility. (Sun, 22 Apr 2012 18:46:02 GMT) Full text and rfc822 format available.

Notification sent to Klaus Stehle <klaus.stehle <at> uni-tuebingen.de>:
bug acknowledged by developer. (Sun, 22 Apr 2012 18:46:02 GMT) Full text and rfc822 format available.

Message #10 received at 11310-done <at> debbugs.gnu.org (full text, mbox):

From: ludo <at> gnu.org (Ludovic Courtès)
To: Klaus Stehle <klaus.stehle <at> uni-tuebingen.de>
Cc: 11310-done <at> debbugs.gnu.org
Subject: Re: bug#11310: wrong conversions of ieee754 from/to foreign endianness
Date: Sun, 22 Apr 2012 20:44:54 +0200
Hi Klaus,

Thanks for the report!  Fixed in
398446c7428b3d98d168fcc3ff170829d3e09f9a, and double-checked on HPPA.

Ludo’.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 21 May 2012 11:24:03 GMT) Full text and rfc822 format available.

This bug report was last modified 11 years and 332 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.