Newlib rounding bug with function lroundf()

This forum is for general developer support questions.

Newlib rounding bug with function lroundf()

Postby xenic » Fri Jun 16, 2017 4:36 pm

The Newlib lroundf() function rounds all numbers between 1.0 and -1.0 to 0. Only numbers with an absolute value less than 0.5 should be rounded to 0. clib2 rounds numbers between 1.0 and -1.0 correctly.

Here is a small program that demonstrates the error when compiled and executed:

Code: Select all
#include <proto/exec.h>
#include <proto/dos.h>
#include <math.h>
#include <stdio.h>

int main()
{
   float x = 0.9;
   float y = -0.9;
   int a = 0;
   int b = 0;

   a = lroundf(x);
   b = lroundf(y);

   printf("x = %f  &  a = %d\n", x, a);
   printf("y = %f  &  b = %d\n", y, b);

   return 0;
}

The output when the above program (named 'test') is compiled with newlib & executed:
6.Ram_Disk:> test
x = 0.900000 & a = 0
y = -0.900000 & b =0

The output when the above program (named 'test') is compiled with clib2 & executed:
6.Ram_Disk:> test
x = 0.900000 & a = 1
y = -0.900000 & b = -1

Can someone compile & test the above program, confirm the erronious result and file a bug report to get this fixed.
Last edited by xenic on Fri Jun 16, 2017 9:11 pm, edited 1 time in total.
AmigaOne X1000 with 2GB memory - OS4.1 FE
xenic
 
Posts: 1020
Joined: Sun Jun 19, 2011 1:06 am

Re: Newlib rounding bug with function lroundf()

Postby broadblues » Fri Jun 16, 2017 5:06 pm

Curiously it only applies to numbers less than 1.0 so nothing as simple as the "rounding direction" being different. (though the spec does say these functionjs ignore the rounding direction anyway).
User avatar
broadblues
AmigaOS Core Developer
AmigaOS Core Developer
 
Posts: 461
Joined: Sat Jun 18, 2011 3:40 am
Location: Portsmouth, UK

Re: Newlib rounding bug with function lroundf()

Postby xenic » Fri Jun 16, 2017 8:57 pm

broadblues wrote:Curiously it only applies to numbers less than 1.0 so nothing as simple as the "rounding direction" being different. (though the spec does say these functionjs ignore the rounding direction anyway).

It does ignore the rounding direction; which is why I should have said it rounds numbers between 0 & 1.0 and between 0 & -1.0 incorrectly. I've edited my original post to reflect that fact. Thanks for pointing it out. I just hope someone can file a bug report now.
AmigaOne X1000 with 2GB memory - OS4.1 FE
xenic
 
Posts: 1020
Joined: Sun Jun 19, 2011 1:06 am

Re: Newlib rounding bug with function lroundf()

Postby broadblues » Sat Jun 17, 2017 4:45 pm

Should be fixed in newlib 53.43
User avatar
broadblues
AmigaOS Core Developer
AmigaOS Core Developer
 
Posts: 461
Joined: Sat Jun 18, 2011 3:40 am
Location: Portsmouth, UK

Re: Newlib rounding bug with function lroundf()

Postby xenic » Sat Jun 17, 2017 5:25 pm

broadblues wrote:Should be fixed in newlib 53.43

Thanks.
AmigaOne X1000 with 2GB memory - OS4.1 FE
xenic
 
Posts: 1020
Joined: Sun Jun 19, 2011 1:06 am


Return to General Developer Support

Who is online

Users browsing this forum: No registered users and 3 guests