Issue 26 in libfixmath: fix16_div bug due to __builtin_clzl

32 views
Skip to first unread message

libfi...@googlecode.com

unread,
Nov 6, 2013, 2:51:49 PM11/6/13
to libfi...@googlegroups.com
Status: New
Owner: ----
Labels: Type-Defect Priority-Medium

New issue 26 by mark.kat...@gmail.com: fix16_div bug due to __builtin_clzl
http://code.google.com/p/libfixmath/issues/detail?id=26

To reproduce issue:

#include <iostream>
#include "fixmath.h"

std::cout <<
fix16_to_float(
fix16_div(
fix16_from_float(10.0f),
fix16_from_float(1.1f)
)
);
std::cout << std::endl;

Expected versus actual output:

expected: 9.09087
actual: 0

Version/operating system/compiler details:

libfixmath version: r64
operating system: Linux Raspberry 3.5.0-22-generic #34-Ubuntu SMP Tue
Jan 8 21:47:00 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
compiler: gcc version 4.7.2 (Ubuntu/Linaro 4.7.2-2ubuntu1)
compilation flags include: -O0 -g -std=c++0x

Details:

Bug seems to be due to __builtin_clzl, which returns 44 for
fix16_from_int(10), causing all sorts of problems. I guess you may be
falsely assuming this function counts the number of leading zeros of a
32-bit integer, whereas really an int may have more than 32 bits.

--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

libfi...@googlecode.com

unread,
Nov 7, 2013, 3:21:09 AM11/7/13
to libfi...@googlegroups.com
Updates:
Owner: Petteri.Aimonen

Comment #1 on issue 26 by Petteri.Aimonen: fix16_div bug due to
__builtin_clzl
http://code.google.com/p/libfixmath/issues/detail?id=26

Hmm, isn't this a duplicate of issue #17, which is already fixed? The macro
should be based on sizeof(long) so that bitcount is taken into account:
https://code.google.com/p/libfixmath/source/browse/trunk/libfixmath/fix16.c#278

Running the attached test.cc on my computer:

petteri@oddish:~/libfixmath/unittests$ uname -a
Linux oddish 3.11.0-12-generic #19-Ubuntu SMP Wed Oct 9 16:20:46 UTC 2013
x86_64 x86_64 x86_64 GNU/Linux
petteri@oddish:~/libfixmath/unittests$ g++ -I ../libfixmath -o test
test.cc ../libfixmath/fix16.c
petteri@oddish:~/libfixmath/unittests$ ./test
sizeof(int) = 4
sizeof(long) = 8
9.09087


Attachments:
test.cc 403 bytes

libfi...@googlecode.com

unread,
Nov 7, 2013, 3:22:34 AM11/7/13
to libfi...@googlegroups.com
Updates:
Owner: Flat...@googlemail.com

Comment #2 on issue 26 by Petteri.Aimonen: fix16_div bug due to
__builtin_clzl
http://code.google.com/p/libfixmath/issues/detail?id=26

Ah, just saw the revision number r64. Upgrade to newest svn and it should
work.

flatmush: maybe we should put a new release on the downloads tab some
time? :)

libfi...@googlecode.com

unread,
Nov 7, 2013, 7:07:39 AM11/7/13
to libfi...@googlegroups.com

Comment #3 on issue 26 by mark.kat...@gmail.com: fix16_div bug due to
__builtin_clzl
http://code.google.com/p/libfixmath/issues/detail?id=26

I would second that suggestion. If this is a known bug that has been fixed
then maybe the default suggested download shouldn't be a version of the
library which still contains this bug.

libfi...@googlecode.com

unread,
Dec 8, 2013, 1:18:50 PM12/8/13
to libfi...@googlegroups.com
Updates:
Status: Done
Cc: Flat...@googlemail.com

Comment #4 on issue 26 by Petteri.Aimonen: fix16_div bug due to
__builtin_clzl
http://code.google.com/p/libfixmath/issues/detail?id=26

flatmush: I took the liberty of marking the downloads as deprecated. Google
Code will discontinue the supports for downloads soon anyway, so maybe it
is better to only have svn.
Reply all
Reply to author
Forward
0 new messages