added trunc, truncf (and truncl on x86) from glibc
should help on bug #1260 git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21350 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
/* Truncate argument to nearest integral value not larger than the argument.
|
||||
Copyright (C) 1997, 1998 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
Contributed by Ulrich Drepper <[email protected]>, 1997.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
02111-1307 USA. */
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "math_private.h"
|
||||
|
||||
|
||||
double
|
||||
__trunc (double x)
|
||||
{
|
||||
int32_t i0, j0;
|
||||
u_int32_t i1;
|
||||
int sx;
|
||||
|
||||
EXTRACT_WORDS (i0, i1, x);
|
||||
sx = i0 & 0x80000000;
|
||||
j0 = ((i0 >> 20) & 0x7ff) - 0x3ff;
|
||||
if (j0 < 20)
|
||||
{
|
||||
if (j0 < 0)
|
||||
/* The magnitude of the number is < 1 so the result is +-0. */
|
||||
INSERT_WORDS (x, sx, 0);
|
||||
else
|
||||
INSERT_WORDS (x, sx | (i0 & ~(0x000fffff >> j0)), 0);
|
||||
}
|
||||
else if (j0 > 51)
|
||||
{
|
||||
if (j0 == 0x400)
|
||||
/* x is inf or NaN. */
|
||||
return x + x;
|
||||
}
|
||||
else
|
||||
{
|
||||
INSERT_WORDS (x, i0, i1 & ~(0xffffffffu >> (j0 - 20)));
|
||||
}
|
||||
|
||||
return x;
|
||||
}
|
||||
weak_alias (__trunc, trunc)
|
||||
#ifdef NO_LONG_DOUBLE
|
||||
strong_alias (__trunc, __truncl)
|
||||
weak_alias (__trunc, truncl)
|
||||
#endif
|
||||
@@ -0,0 +1,52 @@
|
||||
/* Truncate argument to nearest integral value not larger than the argument.
|
||||
Copyright (C) 1997, 1998 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
Contributed by Ulrich Drepper <[email protected]>, 1997.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
02111-1307 USA. */
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "math_private.h"
|
||||
|
||||
|
||||
float
|
||||
__truncf (float x)
|
||||
{
|
||||
int32_t i0, j0;
|
||||
int sx;
|
||||
|
||||
GET_FLOAT_WORD (i0, x);
|
||||
sx = i0 & 0x80000000;
|
||||
j0 = ((i0 >> 23) & 0xff) - 0x7f;
|
||||
if (j0 < 23)
|
||||
{
|
||||
if (j0 < 0)
|
||||
/* The magnitude of the number is < 1 so the result is +-0. */
|
||||
SET_FLOAT_WORD (x, sx);
|
||||
else
|
||||
SET_FLOAT_WORD (x, sx | (i0 & ~(0x007fffff >> j0)));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (j0 == 0x80)
|
||||
/* x is inf or NaN. */
|
||||
return x + x;
|
||||
}
|
||||
|
||||
return x;
|
||||
}
|
||||
weak_alias (__truncf, truncf)
|
||||
@@ -88,6 +88,7 @@ local genericSources =
|
||||
s_sincos.c s_sincosf.c
|
||||
s_tan.c s_tanf.c
|
||||
s_tanh.c s_tanhf.c
|
||||
s_trunc.c s_truncf.c
|
||||
t_exp.c
|
||||
w_acos.c w_acosf.c # w_acosl.c
|
||||
w_acosh.c w_acoshf.c # w_acoshl.c
|
||||
|
||||
@@ -157,6 +157,7 @@ MergeObject posix_gnu_arch_$(TARGET_ARCH)_s.o :
|
||||
s_sin.S s_sinf.S s_sinl.S
|
||||
s_sincos.S s_sincosf.S s_sincosl.S
|
||||
s_tan.S s_tanf.S s_tanl.S
|
||||
s_trunc.S s_truncf.S s_truncl.S
|
||||
;
|
||||
|
||||
MergeObject posix_gnu_arch_$(TARGET_ARCH)_generic.o :
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
/* Truncate double value.
|
||||
Copyright (C) 1997 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
02111-1307 USA. */
|
||||
|
||||
#include <machine/asm.h>
|
||||
|
||||
ENTRY(__trunc)
|
||||
fldl 4(%esp)
|
||||
subl $8, %esp
|
||||
fstcw 4(%esp)
|
||||
movl $0xc00, %edx
|
||||
orl 4(%esp), %edx
|
||||
movl %edx, (%esp)
|
||||
fldcw (%esp)
|
||||
frndint
|
||||
fldcw 4(%esp)
|
||||
addl $8, %esp
|
||||
ret
|
||||
END(__trunc)
|
||||
weak_alias (__trunc, trunc)
|
||||
@@ -0,0 +1,36 @@
|
||||
/* Truncate float value.
|
||||
Copyright (C) 1997 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
02111-1307 USA. */
|
||||
|
||||
#include <machine/asm.h>
|
||||
|
||||
ENTRY(__truncf)
|
||||
flds 4(%esp)
|
||||
subl $8, %esp
|
||||
fstcw 4(%esp)
|
||||
movl $0xc00, %edx
|
||||
orl 4(%esp), %edx
|
||||
movl %edx, (%esp)
|
||||
fldcw (%esp)
|
||||
frndint
|
||||
fldcw 4(%esp)
|
||||
addl $8, %esp
|
||||
ret
|
||||
END(__truncf)
|
||||
weak_alias (__truncf, truncf)
|
||||
@@ -0,0 +1,36 @@
|
||||
/* Truncate long double value.
|
||||
Copyright (C) 1997 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
02111-1307 USA. */
|
||||
|
||||
#include <machine/asm.h>
|
||||
|
||||
ENTRY(__truncl)
|
||||
fldt 4(%esp)
|
||||
subl $8, %esp
|
||||
fstcw 4(%esp)
|
||||
movl $0xc00, %edx
|
||||
orl 4(%esp), %edx
|
||||
movl %edx, (%esp)
|
||||
fldcw (%esp)
|
||||
frndint
|
||||
fldcw 4(%esp)
|
||||
addl $8, %esp
|
||||
ret
|
||||
END(__truncl)
|
||||
weak_alias (__truncl, truncl)
|
||||
Reference in New Issue
Block a user