Initial commit of the floating point related libc functions.
This commit is contained in:
parent
ba9c4033a1
commit
0814ca4b65
|
@ -0,0 +1,48 @@
|
|||
/* $NetBSD: fabs.c,v 1.1 1996/05/12 20:29:41 mark Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1996 Mark Brinicombe
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by Mark Brinicombe
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* fabs(x) returns the absolute value of x.
|
||||
*/
|
||||
|
||||
#ifdef __STDC__
|
||||
double fabs(double x)
|
||||
#else
|
||||
double fabs(x)
|
||||
double x;
|
||||
#endif
|
||||
{
|
||||
if (x < 0)
|
||||
x = -x;
|
||||
return(x);
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
/* $NetBSD: flt_rounds.c,v 1.1 1996/05/12 20:29:09 mark Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1996 Mark Brinicombe
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by Mark Brinicombe
|
||||
* for the NetBSD Project.
|
||||
* 4. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
static const int map[] = {
|
||||
1, /* round to nearest */
|
||||
2, /* round to positive infinity */
|
||||
3, /* round to negative infinity */
|
||||
0 /* round to zero */
|
||||
};
|
||||
|
||||
/*
|
||||
* Return the current FP rounding mode
|
||||
*
|
||||
* Returns:
|
||||
* 0 - round to zero
|
||||
* 1 - round to nearest
|
||||
* 2 - round to postive infinity
|
||||
* 3 - round to negative infinity
|
||||
*
|
||||
* ok all we need to do is get the current FP rounding mode
|
||||
* index our map table and return the appropriate value.
|
||||
*
|
||||
* HOWEVER:
|
||||
* The ARM FPA codes the rounding mode into the actual FP instructions
|
||||
* so there is no such thing as a global rounding mode.
|
||||
* The default is round to nearest if rounding is not explictly specified.
|
||||
* FP instructions generated by GCC will not explicitly specify a rounding
|
||||
* mode.
|
||||
*
|
||||
* So the best we can do it to return the rounding mode FP instructions
|
||||
* use if rounding is not specified which is round to nearest.
|
||||
*
|
||||
* This could change in the future with new floating point emulators or
|
||||
* soft float FP libraries.
|
||||
*/
|
||||
|
||||
int
|
||||
__flt_rounds()
|
||||
{
|
||||
return(map[0]);
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
/* $NetBSD: fpgetmask.c,v 1.1 1996/05/12 20:29:16 mark Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1996 Mark Brinicombe
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by Mark Brinicombe
|
||||
* for the NetBSD Project.
|
||||
* 4. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <ieeefp.h>
|
||||
|
||||
/*
|
||||
* Return the current FP exception mask
|
||||
*/
|
||||
|
||||
fp_except
|
||||
fpgetmask()
|
||||
{
|
||||
abort();
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
/* $NetBSD: fpgetround.c,v 1.1 1996/05/12 20:29:21 mark Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1996 Mark Brinicombe
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by Mark Brinicombe
|
||||
* for the NetBSD Project.
|
||||
* 4. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <ieeefp.h>
|
||||
|
||||
/*
|
||||
* Return the current FP rounding mode
|
||||
*
|
||||
* ok all we need to do is return the current FP rounding mode
|
||||
*
|
||||
* HOWEVER:
|
||||
* The ARM FPA codes the rounding mode into the actual FP instructions
|
||||
* so there is no such thing as a global rounding mode.
|
||||
* The default is round to nearest if rounding is not explictly specified.
|
||||
* FP instructions generated by GCC will not explicitly specify a rounding
|
||||
* mode.
|
||||
*
|
||||
* So the best we can do it to return the rounding mode FP instructions
|
||||
* use if rounding is not specified which is round to nearest.
|
||||
*
|
||||
* This could change in the future with new floating point emulators or
|
||||
* soft float FP libraries.
|
||||
*/
|
||||
|
||||
fp_rnd
|
||||
fpgetround()
|
||||
{
|
||||
return(FP_RN);
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
/* $NetBSD: fpgetsticky.c,v 1.1 1996/05/12 20:29:25 mark Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1996 Mark Brinicombe
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by Mark Brinicombe
|
||||
* for the NetBSD Project.
|
||||
* 4. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <ieeefp.h>
|
||||
|
||||
/*
|
||||
* Return the current FP exception mask
|
||||
*/
|
||||
|
||||
fp_except
|
||||
fpgetsticky()
|
||||
{
|
||||
abort();
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
/* $NetBSD: fpsetmask.c,v 1.1 1996/05/12 20:29:29 mark Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1996 Mark Brinicombe
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by Mark Brinicombe
|
||||
* for the NetBSD Project.
|
||||
* 4. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <ieeefp.h>
|
||||
|
||||
/*
|
||||
* Sets the FP exception mask
|
||||
*/
|
||||
|
||||
fp_except
|
||||
fpsetmask(mask)
|
||||
fp_except mask;
|
||||
{
|
||||
abort();
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
/* $NetBSD: fpsetround.c,v 1.1 1996/05/12 20:29:33 mark Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1996 Mark Brinicombe
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by Mark Brinicombe
|
||||
* for the NetBSD Project.
|
||||
* 4. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <ieeefp.h>
|
||||
|
||||
/*
|
||||
* Return the current FP rounding mode
|
||||
*
|
||||
* ok all we need to do is return the current FP rounding mode
|
||||
*
|
||||
* HOWEVER:
|
||||
* The ARM FPA codes the rounding mode into the actual FP instructions
|
||||
* so there is no such thing as a global rounding mode.
|
||||
* The default is round to nearest if rounding is not explictly specified.
|
||||
* FP instructions generated by GCC will not explicitly specify a rounding
|
||||
* mode.
|
||||
*
|
||||
* All we can do is abort
|
||||
*
|
||||
* This could change in the future with new floating point emulators or
|
||||
* soft float FP libraries.
|
||||
*/
|
||||
|
||||
fp_rnd
|
||||
fpsetround(rnd_dir)
|
||||
fp_rnd rnd_dir;
|
||||
{
|
||||
abort();
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
/* $NetBSD: fpsetsticky.c,v 1.1 1996/05/12 20:29:37 mark Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1996 Mark Brinicombe
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by Mark Brinicombe
|
||||
* for the NetBSD Project.
|
||||
* 4. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <ieeefp.h>
|
||||
|
||||
/*
|
||||
* Sets the FP exception mask
|
||||
*/
|
||||
|
||||
fp_except
|
||||
fpsetsticky(sticky)
|
||||
fp_except sticky;
|
||||
{
|
||||
abort();
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
/* $NetBSD: frexp.c,v 1.1 1996/05/12 20:29:46 mark Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1992, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This software was developed by the Computer Systems Engineering group
|
||||
* at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
|
||||
* contributed to Berkeley.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* from: frexp.c,v 1.1 1993/10/07 00:21:33 cgd Exp $
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)frexp.c 8.1 (Berkeley) 6/4/93";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <machine/ieee.h>
|
||||
|
||||
/*
|
||||
* Split the given value into a fraction in the range [0.5, 1.0) and
|
||||
* an exponent, such that frac * (2^exp) == value. If value is 0,
|
||||
* return 0.
|
||||
*/
|
||||
double
|
||||
frexp(value, eptr)
|
||||
double value;
|
||||
int *eptr;
|
||||
{
|
||||
union {
|
||||
double v;
|
||||
struct ieee_double s;
|
||||
} u;
|
||||
|
||||
if (value) {
|
||||
/*
|
||||
* Fractions in [0.5..1.0) have an exponent of 2^-1.
|
||||
* Leave Inf and NaN alone, however.
|
||||
* WHAT ABOUT DENORMS?
|
||||
*/
|
||||
u.v = value;
|
||||
if (u.s.dbl_exp != DBL_EXP_INFNAN) {
|
||||
*eptr = u.s.dbl_exp - (DBL_EXP_BIAS - 1);
|
||||
u.s.dbl_exp = DBL_EXP_BIAS - 1;
|
||||
}
|
||||
return (u.v);
|
||||
} else {
|
||||
*eptr = 0;
|
||||
return ((double)0);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,149 @@
|
|||
/* $NetBSD: ldexp.c,v 1.1 1996/05/12 20:29:50 mark Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1992, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This software was developed by the Computer Systems Engineering group
|
||||
* at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
|
||||
* contributed to Berkeley.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* from: ldexp.c,v 1.1 1993/10/07 00:21:36 cgd Exp $
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static const char sccsid[] = "@(#)ldexp.c 8.1 (Berkeley) 6/4/93";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <machine/ieee.h>
|
||||
#include <errno.h>
|
||||
|
||||
/*
|
||||
* double ldexp(double val, int exp)
|
||||
* returns: val * (2**exp)
|
||||
*/
|
||||
double
|
||||
ldexp(val, exp)
|
||||
double val;
|
||||
int exp;
|
||||
{
|
||||
register int oldexp, newexp, mulexp;
|
||||
union doub {
|
||||
double v;
|
||||
struct ieee_double s;
|
||||
} u, mul;
|
||||
|
||||
/*
|
||||
* If input is zero, or no change, just return input.
|
||||
* Likewise, if input is Inf or NaN, just return it.
|
||||
*/
|
||||
u.v = val;
|
||||
oldexp = u.s.dbl_exp;
|
||||
if (val == 0 || exp == 0 || oldexp == DBL_EXP_INFNAN)
|
||||
return (val);
|
||||
|
||||
/*
|
||||
* Compute new exponent and check for over/under flow.
|
||||
* Underflow, unfortunately, could mean switching to denormal.
|
||||
* If result out of range, set ERANGE and return 0 if too small
|
||||
* or Inf if too big, with the same sign as the input value.
|
||||
*/
|
||||
newexp = oldexp + exp;
|
||||
if (newexp >= DBL_EXP_INFNAN) {
|
||||
/* u.s.dbl_sign = val < 0; -- already set */
|
||||
u.s.dbl_exp = DBL_EXP_INFNAN;
|
||||
u.s.dbl_frach = u.s.dbl_fracl = 0;
|
||||
errno = ERANGE;
|
||||
return (u.v); /* Inf */
|
||||
}
|
||||
if (newexp <= 0) {
|
||||
/*
|
||||
* The output number is either a denormal or underflows
|
||||
* (see comments in machine/ieee.h).
|
||||
*/
|
||||
if (newexp <= -DBL_FRACBITS) {
|
||||
/* u.s.dbl_sign = val < 0; -- already set */
|
||||
u.s.dbl_exp = 0;
|
||||
u.s.dbl_frach = u.s.dbl_fracl = 0;
|
||||
errno = ERANGE;
|
||||
return (u.v); /* zero */
|
||||
}
|
||||
/*
|
||||
* We are going to produce a denorm. Our `exp' argument
|
||||
* might be as small as -2097, and we cannot compute
|
||||
* 2^-2097, so we may have to do this as many as three
|
||||
* steps (not just two, as for positive `exp's below).
|
||||
*/
|
||||
mul.v = 0;
|
||||
while (exp <= -DBL_EXP_BIAS) {
|
||||
mul.s.dbl_exp = 1;
|
||||
val *= mul.v;
|
||||
exp += DBL_EXP_BIAS - 1;
|
||||
}
|
||||
mul.s.dbl_exp = exp + DBL_EXP_BIAS;
|
||||
val *= mul.v;
|
||||
return (val);
|
||||
}
|
||||
|
||||
/*
|
||||
* Newexp is positive.
|
||||
*
|
||||
* If oldexp is zero, we are starting with a denorm, and simply
|
||||
* adjusting the exponent will produce bogus answers. We need
|
||||
* to fix that first.
|
||||
*/
|
||||
if (oldexp == 0) {
|
||||
/*
|
||||
* Multiply by 2^mulexp to make the number normalizable.
|
||||
* We cannot multiply by more than 2^1023, but `exp'
|
||||
* argument might be as large as 2046. A single
|
||||
* adjustment, however, will normalize the number even
|
||||
* for huge `exp's, and then we can use exponent
|
||||
* arithmetic just as for normal `double's.
|
||||
*/
|
||||
mulexp = exp <= DBL_EXP_BIAS ? exp : DBL_EXP_BIAS;
|
||||
mul.v = 0;
|
||||
mul.s.dbl_exp = mulexp + DBL_EXP_BIAS;
|
||||
val *= mul.v;
|
||||
if (mulexp == exp)
|
||||
return (val);
|
||||
u.v = val;
|
||||
newexp -= mulexp;
|
||||
}
|
||||
|
||||
/*
|
||||
* Both oldexp and newexp are positive; just replace the
|
||||
* old exponent with the new one.
|
||||
*/
|
||||
u.s.dbl_exp = newexp;
|
||||
return (u.v);
|
||||
}
|
|
@ -0,0 +1,104 @@
|
|||
/* $NetBSD: modf.c,v 1.1 1996/05/12 20:29:55 mark Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1994, 1995 Carnegie-Mellon University.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Author: Chris G. Demetriou
|
||||
*
|
||||
* Permission to use, copy, modify and distribute this software and
|
||||
* its documentation is hereby granted, provided that both the copyright
|
||||
* notice and this permission notice appear in all copies of the
|
||||
* software, derivative works or modified versions, and any portions
|
||||
* thereof, and that both notices appear in supporting documentation.
|
||||
*
|
||||
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
|
||||
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
|
||||
* FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
|
||||
*
|
||||
* Carnegie Mellon requests users of this software to return to
|
||||
*
|
||||
* Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
|
||||
* School of Computer Science
|
||||
* Carnegie Mellon University
|
||||
* Pittsburgh PA 15213-3890
|
||||
*
|
||||
* any improvements or extensions that they make and grant Carnegie the
|
||||
* rights to redistribute these changes.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <machine/ieee.h>
|
||||
#include <errno.h>
|
||||
#include <math.h>
|
||||
|
||||
/*
|
||||
* double modf(double val, double *iptr)
|
||||
* returns: f and i such that |f| < 1.0, (f + i) = val, and
|
||||
* sign(f) == sign(i) == sign(val).
|
||||
*
|
||||
* Beware signedness when doing subtraction, and also operand size!
|
||||
*/
|
||||
double
|
||||
modf(val, iptr)
|
||||
double val, *iptr;
|
||||
{
|
||||
union doub {
|
||||
double v;
|
||||
struct ieee_double s;
|
||||
} u, v;
|
||||
u_int64_t frac;
|
||||
|
||||
/*
|
||||
* If input is Inf or NaN, return it and leave i alone.
|
||||
*/
|
||||
u.v = val;
|
||||
if (u.s.dbl_exp == DBL_EXP_INFNAN)
|
||||
return (u.v);
|
||||
|
||||
/*
|
||||
* If input can't have a fractional part, return
|
||||
* (appropriately signed) zero, and make i be the input.
|
||||
*/
|
||||
if ((int)u.s.dbl_exp - DBL_EXP_BIAS > DBL_FRACBITS - 1) {
|
||||
*iptr = u.v;
|
||||
v.v = 0.0;
|
||||
v.s.dbl_sign = u.s.dbl_sign;
|
||||
return (v.v);
|
||||
}
|
||||
|
||||
/*
|
||||
* If |input| < 1.0, return it, and set i to the appropriately
|
||||
* signed zero.
|
||||
*/
|
||||
if (u.s.dbl_exp < DBL_EXP_BIAS) {
|
||||
v.v = 0.0;
|
||||
v.s.dbl_sign = u.s.dbl_sign;
|
||||
*iptr = v.v;
|
||||
return (u.v);
|
||||
}
|
||||
|
||||
/*
|
||||
* There can be a fractional part of the input.
|
||||
* If you look at the math involved for a few seconds, it's
|
||||
* plain to see that the integral part is the input, with the
|
||||
* low (DBL_FRACBITS - (exponent - DBL_EXP_BIAS)) bits zeroed,
|
||||
* the the fractional part is the part with the rest of the
|
||||
* bits zeroed. Just zeroing the high bits to get the
|
||||
* fractional part would yield a fraction in need of
|
||||
* normalization. Therefore, we take the easy way out, and
|
||||
* just use subtraction to get the fractional part.
|
||||
*/
|
||||
v.v = u.v;
|
||||
/* Zero the low bits of the fraction, the sleazy way. */
|
||||
frac = ((u_int64_t)v.s.dbl_frach << 32) + v.s.dbl_fracl;
|
||||
frac >>= DBL_FRACBITS - (u.s.dbl_exp - DBL_EXP_BIAS);
|
||||
frac <<= DBL_FRACBITS - (u.s.dbl_exp - DBL_EXP_BIAS);
|
||||
v.s.dbl_fracl = frac & 0xffffffff;
|
||||
v.s.dbl_frach = frac >> 32;
|
||||
*iptr = v.v;
|
||||
|
||||
u.v -= v.v;
|
||||
u.s.dbl_sign = v.s.dbl_sign;
|
||||
return (u.v);
|
||||
}
|
Loading…
Reference in New Issue