Newlib rounding bug with function lroundf()

This forum is for general developer support questions.
Post Reply
xenic
Posts: 1185
Joined: Sun Jun 19, 2011 12:06 am

Newlib rounding bug with function lroundf()

Post by xenic »

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 8:11 pm, edited 1 time in total.
AmigaOne X1000 with 2GB memory - OS4.1 FE
User avatar
broadblues
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 600
Joined: Sat Jun 18, 2011 2:40 am
Location: Portsmouth, UK
Contact:

Re: Newlib rounding bug with function lroundf()

Post by broadblues »

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).
xenic
Posts: 1185
Joined: Sun Jun 19, 2011 12:06 am

Re: Newlib rounding bug with function lroundf()

Post by xenic »

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
User avatar
broadblues
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 600
Joined: Sat Jun 18, 2011 2:40 am
Location: Portsmouth, UK
Contact:

Re: Newlib rounding bug with function lroundf()

Post by broadblues »

Should be fixed in newlib 53.43
xenic
Posts: 1185
Joined: Sun Jun 19, 2011 12:06 am

Re: Newlib rounding bug with function lroundf()

Post by xenic »

broadblues wrote:Should be fixed in newlib 53.43
Thanks.
AmigaOne X1000 with 2GB memory - OS4.1 FE
Post Reply