Date: Tue, 21 Nov 2017 15:13:44 +0000 From: Khilan Gudka <Khilan.Gudka@cl.cam.ac.uk> To: John Baldwin <jhb@freebsd.org> Cc: freebsd-mips@freebsd.org, Khilan Gudka <Khilan.Gudka@cl.cam.ac.uk> Subject: Re: fabs(-0.0) returns -0.0 Message-ID: <CAPJvC9W%2BZayGtsqYSYctsOb_M0mzVCDMYyzYkc8gmsCTAy%2BsTg@mail.gmail.com> In-Reply-To: <2687660.XtxPXlZaqn@ralph.baldwin.cx> References: <CAPJvC9X2T23qZhWra8J__Fuo6000nxb-w61q5=i%2BBHmpXfmdmA@mail.gmail.com> <2687660.XtxPXlZaqn@ralph.baldwin.cx>
next in thread | previous in thread | raw e-mail | index | archive | help
Alex Richardson has submitted a patch to fix fabs() on FreeBSD: https://reviews.freebsd.org/D13135 Thanks, Khilan On 14 November 2017 at 01:43, John Baldwin <jhb@freebsd.org> wrote: > On Monday, November 13, 2017 10:52:10 PM Khilan Gudka wrote: > > Hi, > > > > The implementation of fabs(3) for MIPS (at least) appears to not be > giving > > the right answer for when -0 is passed, as it returns -0 instead of +0. > The > > implementation of fabs is: > > > > double fabs(double x) { > > if (x < 0) > > return -x; > > return x; > > } > > > > The if-test fails for -0 and thus it is returned. Is this a known issue? > A > > simple fix would be to return x+0.0 instead of just x. > > > > The implication of this is that other functions which rely on fabs, such > as > > hypot, also return -0. For example, hypot(-0.0, 0.0) returns -0 instead > of > > +0. > > The C version of fabs() for 32-bit arm has the same misimplementation btw. > All other architectures implement fabs in assembly in libc. > > -- > John Baldwin >
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAPJvC9W%2BZayGtsqYSYctsOb_M0mzVCDMYyzYkc8gmsCTAy%2BsTg>