Issue 29 in libfixmath: 32-bit multiplication seems to be way off for some values

31 views
Skip to first unread message

libfi...@googlecode.com

unread,
Apr 12, 2014, 10:08:24 PM4/12/14
to libfi...@googlegroups.com
Status: New
Owner: ----
Labels: Type-Defect Priority-Medium

New issue 29 by dan.novi...@gmail.com: 32-bit multiplication seems to be
way off for some values
http://code.google.com/p/libfixmath/issues/detail?id=29

1. Convert a = 9.9 , b = 9.9 into fixed point
2. Call 8-bit, 32-bit, 64-bit multiplication functions
3. Covert the results back to floating point and print them

expected:98.009872 or something close to 98.009995
actual: 113.009872

Latest version, linux 64-bit PC

Trying other values worked pretty well, but it seems that values in [9.2 -
9.9] all give bad results. 8-bit and 64-bit multiply functions worked fine.
There may be other intervals in which the function does not work.



--
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,
Apr 14, 2014, 5:27:15 AM4/14/14
to libfi...@googlegroups.com

Comment #1 on issue 29 by Petteri.Aimonen: 32-bit multiplication seems to
I cannot seem to be able to reproduce this problem:

petteri@oddish:~/libfixmath$ cat test.c
#include <stdio.h>
#include <fix16.h>

int main()
{
fix16_t a = fix16_from_dbl(9.9);
fix16_t b = fix16_from_dbl(9.9);
fix16_t result = fix16_mul(a, b);
printf("%f\n", fix16_to_dbl(result));

return 0;
}
petteri@oddish:~/libfixmath$ gcc -I libfixmath test.c libfixmath/fix16.c
petteri@oddish:~/libfixmath$ ./a.out
98.009872
petteri@oddish:~/libfixmath$ gcc -I libfixmath -DFIXMATH_NO_64BIT=1 test.c
libfixmath/fix16.c
petteri@oddish:~/libfixmath$ ./a.out
98.009872
petteri@oddish:~/libfixmath$ gcc -I libfixmath -DFIXMATH_NO_64BIT=1
-DFIXMATH_OPTIMIZE_8BIT test.c libfixmath/fix16.c
petteri@oddish:~/libfixmath$ ./a.out
98.009872

libfi...@googlecode.com

unread,
Apr 14, 2014, 6:24:57 AM4/14/14
to libfi...@googlegroups.com

Comment #2 on issue 29 by dan.novi...@gmail.com: 32-bit multiplication
seems to be way off for some values
http://code.google.com/p/libfixmath/issues/detail?id=29

My bad, I was using some personalized data types for a MCU on the PC. Got
the original repo and it works.

Info if you want to reproduce it:

$ uname -a
3.11.0-19-generic #33~precise1-Ubuntu SMP Wed Mar 12 21:16:27 UTC 2014
x86_64 x86_64 x86_64 GNU/Linux

typedef char int8_t;
typedef unsigned char uint8_t;
typedef int int16_t;
typedef unsigned int uint16_t;
typedef unsigned long uint32_t;
typedef long int32_t;
typedef long long int64_t;
typedef unsigned long long uint64_t;

libfi...@googlecode.com

unread,
Apr 15, 2014, 10:39:44 AM4/15/14
to libfi...@googlegroups.com
Updates:
Status: Invalid

Comment #3 on issue 29 by Petteri.Aimonen: 32-bit multiplication seems to
(No comment was entered for this change.)
Reply all
Reply to author
Forward
0 new messages