mirror of
https://git.planet-casio.com/Lephenixnoir/OpenLibm.git
synced 2025-04-05 12:58:24 +02:00
Compare commits
26 commits
Author | SHA1 | Date | |
---|---|---|---|
|
9828d2e3f2 | ||
|
65aaba96e1 | ||
|
feba6242e4 | ||
|
63c74a4b92 | ||
|
e67d553764 | ||
|
08f772e6ab | ||
|
1cf5a91b46 | ||
|
8afd538dc8 | ||
|
39ede78797 | ||
|
668336366e | ||
|
d241d4f77a | ||
|
f052f42bb3 | ||
|
711654eeab | ||
|
aeab19f47e | ||
|
5449705906 | ||
|
98f87135b0 | ||
|
6a85b33182 | ||
|
40dac9dd77 | ||
|
2d10c90c77 | ||
|
5d70ac564c | ||
|
63aa8757f3 | ||
|
9152b0d1b0 | ||
|
3cb804556f | ||
|
c8561015a4 | ||
|
be31bff11d | ||
|
eb21e8abd1 |
31 changed files with 218 additions and 81 deletions
35
Make.inc
35
Make.inc
|
@ -10,41 +10,40 @@ VERSION = 0.7.0
|
|||
SOMAJOR = 3
|
||||
SOMINOR = 0
|
||||
DESTDIR =
|
||||
prefix = /usr/local
|
||||
bindir = $(prefix)/bin
|
||||
libdir = $(prefix)/lib
|
||||
includedir = $(prefix)/include
|
||||
prefix ?= /usr/local
|
||||
bindir ?= $(prefix)/bin
|
||||
libdir ?= $(prefix)/lib
|
||||
includedir ?= $(prefix)/include
|
||||
|
||||
ifeq ($(OS), FreeBSD)
|
||||
pkgconfigdir = $(prefix)/libdata/pkgconfig
|
||||
pkgconfigdir ?= $(prefix)/libdata/pkgconfig
|
||||
else
|
||||
pkgconfigdir = $(libdir)/pkgconfig
|
||||
pkgconfigdir ?= $(libdir)/pkgconfig
|
||||
endif
|
||||
|
||||
USEGCC = 1
|
||||
USECLANG = 0
|
||||
USEGCC ?= 1
|
||||
USECLANG ?= 0
|
||||
|
||||
ifneq (,$(findstring $(OS),Darwin FreeBSD OpenBSD))
|
||||
USEGCC = 0
|
||||
USECLANG = 1
|
||||
USEGCC ?= 0
|
||||
USECLANG ?= 1
|
||||
endif
|
||||
|
||||
AR = $(TOOLPREFIX)ar
|
||||
|
||||
ifeq ($(ARCH),wasm32)
|
||||
CC = clang-8
|
||||
USEGCC = 0
|
||||
CFLAGS_add += -fno-builtin -fno-strict-aliasing
|
||||
USECLANG = 1
|
||||
TOOLPREFIX = llvm-
|
||||
endif
|
||||
|
||||
AR ?= $(TOOLPREFIX)ar
|
||||
|
||||
ifeq ($(USECLANG),1)
|
||||
USEGCC = 0
|
||||
USEGCC ?= 0
|
||||
CC = clang
|
||||
CFLAGS_add += -fno-builtin -fno-strict-aliasing
|
||||
endif
|
||||
|
||||
ifeq ($(USEGCC),1)
|
||||
CC = $(TOOLPREFIX)gcc
|
||||
CC ?= $(TOOLPREFIX)gcc
|
||||
CFLAGS_add += -fno-gnu89-inline -fno-builtin
|
||||
endif
|
||||
|
||||
|
@ -106,7 +105,9 @@ else
|
|||
SHLIB_EXT = so
|
||||
SONAME_FLAG = -soname
|
||||
endif
|
||||
ifneq ($(ARCH),sh3eb)
|
||||
CFLAGS_add += -fPIC
|
||||
endif
|
||||
shlibdir = $(libdir)
|
||||
endif
|
||||
|
||||
|
|
18
Makefile
18
Makefile
|
@ -80,7 +80,7 @@ test/test-float: libopenlibm.$(OLM_MAJOR_MINOR_SHLIB_EXT)
|
|||
$(MAKE) -C test test-float
|
||||
|
||||
clean:
|
||||
rm -f aarch64/*.o amd64/*.o arm/*.o bsdsrc/*.o i387/*.o ld80/*.o ld128/*.o src/*.o powerpc/*.o mips/*.o s390/*.o
|
||||
rm -f aarch64/*.o amd64/*.o arm/*.o bsdsrc/*.o i387/*.o ld80/*.o ld128/*.o src/*.o powerpc/*.o mips/*.o s390/*.o sh3eb/*.o
|
||||
rm -f libopenlibm.a libopenlibm.*$(SHLIB_EXT)*
|
||||
$(MAKE) -C test clean
|
||||
|
||||
|
@ -93,6 +93,9 @@ install-static: libopenlibm.a
|
|||
mkdir -p $(DESTDIR)$(libdir)
|
||||
cp -RpP -f libopenlibm.a $(DESTDIR)$(libdir)/
|
||||
|
||||
install-static-superh: install-static
|
||||
ln -sf libopenlibm.a $(DESTDIR)$(libdir)/libm.a
|
||||
|
||||
install-shared: libopenlibm.$(OLM_MAJOR_MINOR_SHLIB_EXT)
|
||||
mkdir -p $(DESTDIR)$(shlibdir)
|
||||
cp -RpP -f libopenlibm.*$(SHLIB_EXT)* $(DESTDIR)$(shlibdir)/
|
||||
|
@ -106,4 +109,15 @@ install-headers:
|
|||
cp -RpP -f include/*.h $(DESTDIR)$(includedir)/openlibm
|
||||
cp -RpP -f src/*.h $(DESTDIR)$(includedir)/openlibm
|
||||
|
||||
install: install-static install-shared install-pkgconfig install-headers
|
||||
install-headers-superh:
|
||||
mkdir -p $(DESTDIR)$(includedir)
|
||||
cp -RpP -f \
|
||||
include/openlibm.h \
|
||||
include/openlibm_complex.h \
|
||||
include/openlibm_defs.h \
|
||||
include/openlibm_fenv.h \
|
||||
include/openlibm_fenv_sh3eb.h \
|
||||
include/openlibm_math.h \
|
||||
$(DESTDIR)$(includedir)
|
||||
|
||||
install: install-static install-shared install-pkgconfig
|
||||
|
|
61
README.md
61
README.md
|
@ -1,57 +1,60 @@
|
|||
# Soft-FP sh3eb port of OpenLibm
|
||||
|
||||
This is a fork of [OpenLibm](https://github.com/JuliaMath/openlibm) with
|
||||
support for the sh3eb architecture, intended for add-in programming on fx-9860G
|
||||
and fx-CG 50.
|
||||
This is a fork of [OpenLibm](https://github.com/JuliaMath/openlibm) with support for the sh3eb architecture, intended for add-in programming on SuperH CASIO calculators.
|
||||
|
||||
## Installing with GiteaPC
|
||||
|
||||
This library can be installed automatically with [GiteaPC](https://gitea.planet-casio.com/Lephenixnoir/GiteaPC).
|
||||
This library can be installed automatically as part of the fxSDK with [GiteaPC](https://gitea.planet-casio.com/Lephenixnoir/GiteaPC):
|
||||
|
||||
```
|
||||
```bash
|
||||
% giteapc install Lephenixnoir/OpenLibm
|
||||
```
|
||||
|
||||
## Building manually
|
||||
|
||||
You will need a GCC toolchain built with `--target=sh3eb-elf`, such as the
|
||||
`sh-elf-gcc` commonly used on Planète Casio.
|
||||
You will need a GCC toolchain built with `--target=sh3eb-elf`, such as the [`sh-elf-gcc`](https://gitea.planet-casio.com/Lephenixnoir/sh-elf-gcc) commonly used on Planète Casio.
|
||||
|
||||
First locate the compiler's install directory. This is normally the
|
||||
`lib/gcc/sh3eb-elf/<version>/` folder inside the install path of the compiler.
|
||||
You can install directly in the internal folder of your compiler, or somewhere else if you have a more detailed setup.
|
||||
|
||||
```
|
||||
% PREFIX=$(sh-elf-gcc --print-search-dirs | grep install | sed 's/install: //')
|
||||
```bash
|
||||
# Example 1: Use the compiler's internal folder
|
||||
% COMPILER_DIR="$(sh-elf-gcc --print-file-name=.)"
|
||||
% LIBDIR="$COMPILER_DIR"
|
||||
% INCDIR="$COMPILER_DIR/include"
|
||||
# Example 2: Using the fxSDK's custom setup
|
||||
% LIBDIR="$(fxsdk path lib)"
|
||||
% INCDIR="$(fxsdk path include)"
|
||||
```
|
||||
|
||||
You can then build and install the static `libopenlibm.a` archive and the headers.
|
||||
You can then build and install the static library and the headers.
|
||||
|
||||
```
|
||||
% make USEGCC=1 TOOLPREFIX=sh-elf- libdir="$PREFIX" includedir="$PREFIX/include" install-static install-headers
|
||||
```bash
|
||||
% make USEGCC=1 TOOLPREFIX=sh-elf- AR=sh-elf-ar CC=sh-elf-gcc \
|
||||
libdir="$LIBDIR" includedir="$INCDIR" \
|
||||
install-static-superh install-headers-superh
|
||||
```
|
||||
|
||||
## Using in a Makefile-based add-in
|
||||
The `-superh` targets differ from the the normal targets in the following ways:
|
||||
|
||||
Link with `-lopenlibm` as you would do with `-lm`. Since OpenLibm headers
|
||||
reference themselves by file name (`#include <openlibm_complex.h>`) even though
|
||||
they are installed in a subfolder, you need a `-I` flag:
|
||||
* `install-static-superh` also creates a symlink `libm.a -> libopenlibm.a`.
|
||||
* `install-headers-superh` installs directly in `$LIBDIR` instead of `$LIBDIR/openlibm` since OpenLibm headers reference each other without that prefix and enforcing the correct `-I` in every project is quite painful. In addition, it skips internal and non-SuperH headers.
|
||||
|
||||
## Using the library
|
||||
|
||||
Include the headers `<openlibm_complex.h>`, `<openlibm_fenv.h>` and `<openlibm_math.h>`. Or, if you are using a suitable libc like [fxlibc](https://gitea.planet-casio.com/Vhex-Kernel-Core/fxlibc/), include directly the standard headers `<complex.h>`, `<fenv.h>` and `<math.h>`.
|
||||
|
||||
Link with `-lm`. In a Makefile, update your `LDFLAGS`:
|
||||
|
||||
```
|
||||
CFLAGS += -I $(shell sh-elf-gcc -print-file-name=include/openlibm)
|
||||
LDFLAGS += -lopenlibm
|
||||
LDFLAGS += -lm
|
||||
```
|
||||
|
||||
## Using in a CMake-based add-in
|
||||
In CMake, use [`target_link_libraries()`](https://cmake.org/cmake/help/latest/command/target_link_libraries.html):
|
||||
|
||||
When using CMake with the fxSDK, add the include folder and library like this.
|
||||
|
||||
```
|
||||
target_include_directories(<TARGET> PRIVATE "${FXSDK_COMPILER_INSTALL}/include/openlibm")
|
||||
target_link_libraries(<TARGET> -lopenlibm)
|
||||
```cmake
|
||||
target_link_libraries(<TARGET> PUBLIC -lm)
|
||||
```
|
||||
|
||||
## README and Licensing
|
||||
|
||||
See the original README file in [README-OpenLibm.md](README-OpenLibm.md).
|
||||
OpenLibm contains code covered by various licenses, see
|
||||
[LICENSE.md](LICENSE.md).
|
||||
See the original README file in [README-OpenLibm.md](README-OpenLibm.md). OpenLibm contains code covered by various licenses, see [LICENSE.md](LICENSE.md).
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
* $FreeBSD: src/lib/msun/arm/fenv.c,v 1.3 2011/10/16 05:37:56 das Exp $
|
||||
*/
|
||||
|
||||
#define __fenv_static
|
||||
#include <openlibm_fenv.h>
|
||||
|
||||
#ifdef __GNUC_GNU_INLINE__
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
#include "bsd_fpu.h"
|
||||
#include "math_private.h"
|
||||
|
||||
#ifndef OPENLIBM_USE_HOST_FENV_H
|
||||
#ifdef _WIN32
|
||||
#define __fenv_static OLM_DLLEXPORT
|
||||
#endif
|
||||
#include <openlibm_fenv.h>
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
* acknowledged.
|
||||
*/
|
||||
|
||||
#include <float.h>
|
||||
#include <openlibm_math.h>
|
||||
|
||||
#include "mathimpl.h"
|
||||
|
@ -312,3 +313,7 @@ neg_gam(x)
|
|||
if (sgn < 0) y = -y;
|
||||
return (M_PI / (y*z));
|
||||
}
|
||||
|
||||
#if (LDBL_MANT_DIG == 53)
|
||||
openlibm_weak_reference(tgamma, tgammal);
|
||||
#endif
|
||||
|
|
13
giteapc.make
13
giteapc.make
|
@ -1,17 +1,22 @@
|
|||
# giteapc: version=1 depends=Lephenixnoir/sh-elf-gcc
|
||||
# giteapc: version=1 depends=Lephenixnoir/fxsdk,Lephenixnoir/sh-elf-gcc
|
||||
|
||||
-include giteapc-config.make
|
||||
|
||||
PREFIX ?= $(shell sh-elf-gcc --print-search-dirs | grep install | sed 's/install: //')
|
||||
# Use the fxSDK's default paths unless specified otherwise on the command line
|
||||
LIBDIR ?= $(shell fxsdk path lib)
|
||||
INCDIR ?= $(shell fxsdk path include)
|
||||
|
||||
FLAGS := USEGCC=1 TOOLPREFIX=sh-elf- CC=sh-elf-gcc AR=sh-elf-ar \
|
||||
libdir="$(LIBDIR)" includedir="$(INCDIR)"
|
||||
|
||||
configure:
|
||||
@ true
|
||||
|
||||
build:
|
||||
@ make USEGCC=1 TOOLPREFIX=sh-elf- libdir="$(PREFIX)" includedir="$(PREFIX)/include"
|
||||
@ make $(FLAGS)
|
||||
|
||||
install:
|
||||
@ make USEGCC=1 TOOLPREFIX=sh-elf- libdir="$(PREFIX)" includedir="$(PREFIX)/include" install-static install-headers
|
||||
@ make $(FLAGS) install-static-superh install-headers-superh
|
||||
|
||||
uninstall:
|
||||
@ echo "uninstall not supported for OpenLibm, skipping"
|
||||
|
|
|
@ -30,7 +30,6 @@
|
|||
#define _FENV_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include "cdefs-compat.h"
|
||||
|
||||
#ifndef __fenv_static
|
||||
#define __fenv_static static
|
||||
|
@ -57,7 +56,10 @@ typedef uint32_t fexcept_t;
|
|||
#define FE_DOWNWARD 0x0003
|
||||
#define _ROUND_MASK (FE_TONEAREST | FE_DOWNWARD | \
|
||||
FE_UPWARD | FE_TOWARDZERO)
|
||||
__BEGIN_DECLS
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Default floating-point environment */
|
||||
extern const fenv_t __fe_dfl_env;
|
||||
|
@ -89,6 +91,8 @@ int fegetexcept(void);
|
|||
|
||||
#endif /* __BSD_VISIBLE */
|
||||
|
||||
__END_DECLS
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* !_FENV_H_ */
|
||||
|
|
|
@ -304,6 +304,7 @@ OLM_DLLEXPORT double trunc(double);
|
|||
* BSD math library entry points
|
||||
*/
|
||||
#if __BSD_VISIBLE
|
||||
OLM_DLLEXPORT int isinff(float) __pure2;
|
||||
OLM_DLLEXPORT int isnanf(float) __pure2;
|
||||
|
||||
/*
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#define __fenv_static
|
||||
#include <openlibm_fenv.h>
|
||||
|
||||
#ifdef __GNUC_GNU_INLINE__
|
||||
|
|
|
@ -55,7 +55,6 @@
|
|||
extern int __softfloat_float_exception_flags;
|
||||
extern int __softfloat_float_exception_mask;
|
||||
extern int __softfloat_float_rounding_mode;
|
||||
void __softfloat_float_raise(int);
|
||||
|
||||
__fenv_static inline int
|
||||
feclearexcept(int __excepts)
|
||||
|
@ -86,7 +85,7 @@ __fenv_static inline int
|
|||
feraiseexcept(int __excepts)
|
||||
{
|
||||
|
||||
__softfloat_float_raise(__excepts);
|
||||
__softfloat_float_exception_flags |= __excepts;
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
@ -181,4 +180,4 @@ fegetexcept(void)
|
|||
return (__softfloat_float_exception_mask);
|
||||
}
|
||||
|
||||
#endif /* __BSD_VISIBLE */
|
||||
#endif /* __BSD_VISIBLE */
|
||||
|
|
|
@ -29,6 +29,8 @@
|
|||
#define __fenv_static
|
||||
#include "openlibm_fenv.h"
|
||||
|
||||
#include <float.h>
|
||||
|
||||
#ifdef __GNUC_GNU_INLINE__
|
||||
#error "This file must be compiled with C99 'inline' semantics"
|
||||
#endif
|
||||
|
@ -39,6 +41,10 @@
|
|||
*/
|
||||
const fenv_t __fe_dfl_env = 0;
|
||||
|
||||
int __softfloat_float_exception_flags = 0;
|
||||
int __softfloat_float_exception_mask = 0;
|
||||
int __softfloat_float_rounding_mode = FLT_ROUNDS;
|
||||
|
||||
#define __set_env(env, flags, mask, rnd) env = ((flags) \
|
||||
| (mask)<<_FPUSW_SHIFT \
|
||||
| (rnd) << 24)
|
||||
|
|
|
@ -34,9 +34,15 @@
|
|||
#else
|
||||
#ifdef __ELF__
|
||||
#ifdef __STDC__
|
||||
#if defined(__sh3__)
|
||||
#define openlibm_weak_reference(sym,alias) \
|
||||
__asm__(".weak _" #alias); \
|
||||
__asm__(".equ _" #alias ", _" #sym)
|
||||
#else
|
||||
#define openlibm_weak_reference(sym,alias) \
|
||||
__asm__(".weak " #alias); \
|
||||
__asm__(".equ " #alias ", " #sym)
|
||||
#endif /* __sh3__ */
|
||||
#ifdef __warn_references
|
||||
#define openlibm_warn_references(sym,msg) __warn_references(sym,msg)
|
||||
#else
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
* acosh(NaN) is NaN without signal.
|
||||
*/
|
||||
|
||||
#include <float.h>
|
||||
#include <openlibm_math.h>
|
||||
|
||||
#include "math_private.h"
|
||||
|
@ -61,3 +62,7 @@ __ieee754_acosh(double x)
|
|||
return log1p(t+sqrt(2.0*t+t*t));
|
||||
}
|
||||
}
|
||||
|
||||
#if (LDBL_MANT_DIG == 53)
|
||||
openlibm_weak_reference(acosh, acoshl);
|
||||
#endif
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include <float.h>
|
||||
#include <openlibm_math.h>
|
||||
|
||||
#include "math_private.h"
|
||||
|
@ -61,3 +62,7 @@ __ieee754_atanh(double x)
|
|||
t = 0.5*log1p((x+x)/(one-x));
|
||||
if(hx>=0) return t; else return -t;
|
||||
}
|
||||
|
||||
#if (LDBL_MANT_DIG == 53)
|
||||
openlibm_weak_reference(atanh, atanhl);
|
||||
#endif
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
* only cosh(0)=1 is exact for finite x.
|
||||
*/
|
||||
|
||||
#include <float.h>
|
||||
#include <openlibm_math.h>
|
||||
|
||||
#include "math_private.h"
|
||||
|
@ -78,3 +79,7 @@ __ieee754_cosh(double x)
|
|||
/* |x| > overflowthresold, cosh(x) overflow */
|
||||
return huge*huge;
|
||||
}
|
||||
|
||||
#if (LDBL_MANT_DIG == 53)
|
||||
openlibm_weak_reference(cosh, coshl);
|
||||
#endif
|
||||
|
|
|
@ -165,3 +165,7 @@ __ieee754_exp(double x) /* default IEEE double exp */
|
|||
return y*twopk*twom1000;
|
||||
}
|
||||
}
|
||||
|
||||
#if (LDBL_MANT_DIG == 53)
|
||||
openlibm_weak_reference(exp, expl);
|
||||
#endif
|
||||
|
|
|
@ -82,7 +82,7 @@ hypotl(long double x, long double y)
|
|||
man_t manh, manl;
|
||||
GET_LDBL_MAN(manh,manl,b);
|
||||
if((manh|manl)==0) return a;
|
||||
t1=0;
|
||||
t1=1;
|
||||
SET_HIGH_WORD(t1,ESW(MAX_EXP-2)); /* t1=2^(MAX_EXP-2) */
|
||||
b *= t1;
|
||||
a *= t1;
|
||||
|
|
|
@ -65,6 +65,7 @@
|
|||
* to produce the hexadecimal values shown.
|
||||
*/
|
||||
|
||||
#include <float.h>
|
||||
#include <openlibm_math.h>
|
||||
|
||||
#include "math_private.h"
|
||||
|
@ -139,3 +140,7 @@ __ieee754_log(double x)
|
|||
return dk*ln2_hi-((s*(f-R)-dk*ln2_lo)-f);
|
||||
}
|
||||
}
|
||||
|
||||
#if (LDBL_MANT_DIG == 53)
|
||||
openlibm_weak_reference(log, logl);
|
||||
#endif
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
* in not-quite-routine extra precision.
|
||||
*/
|
||||
|
||||
#include <float.h>
|
||||
#include <openlibm_math.h>
|
||||
|
||||
#include "math_private.h"
|
||||
|
@ -86,3 +87,7 @@ __ieee754_log10(double x)
|
|||
|
||||
return val_lo + val_hi;
|
||||
}
|
||||
|
||||
#if (LDBL_MANT_DIG == 53)
|
||||
openlibm_weak_reference(log10, log10l);
|
||||
#endif
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
* in not-quite-routine extra precision.
|
||||
*/
|
||||
|
||||
#include <float.h>
|
||||
#include <openlibm_math.h>
|
||||
|
||||
#include "math_private.h"
|
||||
|
@ -109,3 +110,7 @@ __ieee754_log2(double x)
|
|||
|
||||
return val_lo + val_hi;
|
||||
}
|
||||
|
||||
#if (LDBL_MANT_DIG == 53)
|
||||
openlibm_weak_reference(log2, log2l);
|
||||
#endif
|
||||
|
|
|
@ -57,6 +57,7 @@
|
|||
* to produce the hexadecimal values shown.
|
||||
*/
|
||||
|
||||
#include <float.h>
|
||||
#include <openlibm_math.h>
|
||||
|
||||
#include "math_private.h"
|
||||
|
@ -310,3 +311,7 @@ __ieee754_pow(double x, double y)
|
|||
else SET_HIGH_WORD(z,j);
|
||||
return s*z;
|
||||
}
|
||||
|
||||
#if (LDBL_MANT_DIG == 53)
|
||||
openlibm_weak_reference(pow, powl);
|
||||
#endif
|
||||
|
|
26
src/e_powf.c
26
src/e_powf.c
|
@ -25,6 +25,9 @@ bp[] = {1.0, 1.5,},
|
|||
dp_h[] = { 0.0, 5.84960938e-01,}, /* 0x3f15c000 */
|
||||
dp_l[] = { 0.0, 1.56322085e-06,}, /* 0x35d1cfdc */
|
||||
zero = 0.0,
|
||||
half = 0.5,
|
||||
qrtr = 0.25,
|
||||
thrd = 3.33333343e-01, /* 0x3eaaaaab */
|
||||
one = 1.0,
|
||||
two = 2.0,
|
||||
two24 = 16777216.0, /* 0x4b800000 */
|
||||
|
@ -74,7 +77,7 @@ __ieee754_powf(float x, float y)
|
|||
/* y!=zero: result is NaN if either arg is NaN */
|
||||
if(ix > 0x7f800000 ||
|
||||
iy > 0x7f800000)
|
||||
return (x+0.0F)+(y+0.0F);
|
||||
return nan_mix(x, y);
|
||||
|
||||
/* determine if y is an odd int when x < 0
|
||||
* yisint = 0 ... y is not an integer
|
||||
|
@ -103,15 +106,10 @@ __ieee754_powf(float x, float y)
|
|||
if(iy==0x3f800000) { /* y is +-1 */
|
||||
if(hy<0) return one/x; else return x;
|
||||
}
|
||||
if(hy==0x40000000) return x*x; /* y is 2 */
|
||||
if(hy==0x40400000) return x*x*x; /* y is 3 */
|
||||
if(hy==0x40800000) { /* y is 4 */
|
||||
u = x*x;
|
||||
return u*u;
|
||||
}
|
||||
if(hy==0x3f000000) { /* y is 0.5 */
|
||||
if(hy==0x40000000) return x*x; /* y is 2 */
|
||||
if(hy==0x3f000000) { /* y is 0.5 */
|
||||
if(hx>=0) /* x >= +0 */
|
||||
return __ieee754_sqrtf(x);
|
||||
return __ieee754_sqrtf(x);
|
||||
}
|
||||
|
||||
ax = fabsf(x);
|
||||
|
@ -139,12 +137,12 @@ __ieee754_powf(float x, float y)
|
|||
/* |y| is huge */
|
||||
if(iy>0x4d000000) { /* if |y| > 2**27 */
|
||||
/* over/underflow if x is not close to one */
|
||||
if(ix<0x3f7ffff8) return (hy<0)? sn*huge*huge:sn*tiny*tiny;
|
||||
if(ix<0x3f7ffff7) return (hy<0)? sn*huge*huge:sn*tiny*tiny;
|
||||
if(ix>0x3f800007) return (hy>0)? sn*huge*huge:sn*tiny*tiny;
|
||||
/* now |1-x| is tiny <= 2**-20, suffice to compute
|
||||
log(x) by x-x^2/2+x^3/3-x^4/4 */
|
||||
t = ax-1; /* t has 20 trailing zeros */
|
||||
w = (t*t)*((float)0.5-t*((float)0.333333333333-t*(float)0.25));
|
||||
w = (t*t)*(half-t*(thrd-t*qrtr));
|
||||
u = ivln2_h*t; /* ivln2_h has 16 sig. bits */
|
||||
v = t*ivln2_l-w*ivln2;
|
||||
t1 = u+v;
|
||||
|
@ -183,10 +181,10 @@ __ieee754_powf(float x, float y)
|
|||
r = s2*s2*(L1+s2*(L2+s2*(L3+s2*(L4+s2*(L5+s2*L6)))));
|
||||
r += s_l*(s_h+s);
|
||||
s2 = s_h*s_h;
|
||||
t_h = (float)3.0+s2+r;
|
||||
t_h = 3+s2+r;
|
||||
GET_FLOAT_WORD(is,t_h);
|
||||
SET_FLOAT_WORD(t_h,is&0xfffff000);
|
||||
t_l = r-((t_h-(float)3.0)-s2);
|
||||
t_l = r-((t_h-3)-s2);
|
||||
/* u+v = s*(1+...) */
|
||||
u = s_h*t_h;
|
||||
v = s_l*t_h+t_l*s;
|
||||
|
@ -198,7 +196,7 @@ __ieee754_powf(float x, float y)
|
|||
z_h = cp_h*p_h; /* cp_h+cp_l = 2/(3*log2) */
|
||||
z_l = cp_l*p_h+p_l*cp+dp_l[k];
|
||||
/* log2(ax) = (s+..)*2/(3*log2) = n + dp_h + z_h + z_l */
|
||||
t = (float)n;
|
||||
t = n;
|
||||
t1 = (((z_h+z_l)+dp_h[k])+t);
|
||||
GET_FLOAT_WORD(is,t1);
|
||||
SET_FLOAT_WORD(t1,is&0xfffff000);
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
* only sinh(0)=0 is exact for finite x.
|
||||
*/
|
||||
|
||||
#include <float.h>
|
||||
#include <openlibm_math.h>
|
||||
|
||||
#include "math_private.h"
|
||||
|
@ -72,3 +73,7 @@ __ieee754_sinh(double x)
|
|||
/* |x| > overflowthresold, sinh(x) overflow */
|
||||
return x*shuge;
|
||||
}
|
||||
|
||||
#if (LDBL_MANT_DIG == 53)
|
||||
openlibm_weak_reference(sinh, sinhl);
|
||||
#endif
|
||||
|
|
|
@ -203,10 +203,9 @@ do { \
|
|||
} while (0)
|
||||
|
||||
|
||||
//VBS
|
||||
#ifndef __FreeBSD__
|
||||
#define STRICT_ASSIGN(type, lval, rval) ((lval) = (rval))
|
||||
|
||||
/* VBS
|
||||
#else
|
||||
#ifdef FLT_EVAL_METHOD
|
||||
// Attempt to get strict C99 semantics for assignment with non-C99 compilers.
|
||||
#if FLT_EVAL_METHOD == 0 || __GNUC__ == 0
|
||||
|
@ -215,7 +214,7 @@ do { \
|
|||
#define STRICT_ASSIGN(type, lval, rval) do { \
|
||||
volatile type __lval; \
|
||||
\
|
||||
if (sizeof(type) >= sizeof(double)) \
|
||||
if (sizeof(type) >= sizeof(long double)) \
|
||||
(lval) = (rval); \
|
||||
else { \
|
||||
__lval = (rval); \
|
||||
|
@ -224,13 +223,31 @@ do { \
|
|||
} while (0)
|
||||
#endif
|
||||
#endif
|
||||
*/
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Common routine to process the arguments to nan(), nanf(), and nanl().
|
||||
*/
|
||||
void __scan_nan(u_int32_t *__words, int __num_words, const char *__s);
|
||||
|
||||
/*
|
||||
* Mix 1 or 2 NaNs. First add 0 to each arg. This normally just turns
|
||||
* signaling NaNs into quiet NaNs by setting a quiet bit. We do this
|
||||
* because we want to never return a signaling NaN, and also because we
|
||||
* don't want the quiet bit to affect the result. Then mix the converted
|
||||
* args using addition. The result is typically the arg whose mantissa
|
||||
* bits (considered as in integer) are largest.
|
||||
*
|
||||
* Technical complications: the result in bits might depend on the precision
|
||||
* and/or on compiler optimizations, especially when different register sets
|
||||
* are used for different precisions. Try to make the result not depend on
|
||||
* at least the precision by always doing the main mixing step in long double
|
||||
* precision. Try to reduce dependencies on optimizations by adding the
|
||||
* the 0's in different precisions (unless everything is in long double
|
||||
* precision).
|
||||
*/
|
||||
#define nan_mix(x, y) (((x) + 0.0L) + ((y) + 0))
|
||||
|
||||
#ifdef __GNUCLIKE_ASM
|
||||
|
||||
/* Asm versions of some functions. */
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
* := sign(x)*log1p(|x| + x^2/(1 + sqrt(1+x^2)))
|
||||
*/
|
||||
|
||||
#include <float.h>
|
||||
#include <openlibm_math.h>
|
||||
|
||||
#include "math_private.h"
|
||||
|
@ -55,3 +56,7 @@ asinh(double x)
|
|||
}
|
||||
if(hx>0) return w; else return -w;
|
||||
}
|
||||
|
||||
#if (LDBL_MANT_DIG == 53)
|
||||
openlibm_weak_reference(asinh, asinhl);
|
||||
#endif
|
||||
|
|
|
@ -107,6 +107,7 @@
|
|||
* erfc/erf(NaN) is NaN
|
||||
*/
|
||||
|
||||
#include <float.h>
|
||||
#include <openlibm_math.h>
|
||||
|
||||
#include "math_private.h"
|
||||
|
@ -299,3 +300,8 @@ erfc(double x)
|
|||
if(hx>0) return tiny*tiny; else return two-tiny;
|
||||
}
|
||||
}
|
||||
|
||||
#if (LDBL_MANT_DIG == 53)
|
||||
openlibm_weak_reference(erf, erfl);
|
||||
openlibm_weak_reference(erfc, erfcl);
|
||||
#endif
|
||||
|
|
|
@ -215,3 +215,7 @@ expm1(double x)
|
|||
}
|
||||
return y;
|
||||
}
|
||||
|
||||
#if (LDBL_MANT_DIG == 53)
|
||||
openlibm_weak_reference(expm1, expm1l);
|
||||
#endif
|
||||
|
|
|
@ -173,3 +173,7 @@ log1p(double x)
|
|||
if(k==0) return f-(hfsq-s*(hfsq+R)); else
|
||||
return k*ln2_hi-((hfsq-(s*(hfsq+R)+(k*ln2_lo+c)))-f);
|
||||
}
|
||||
|
||||
#if (LDBL_MANT_DIG == 53)
|
||||
openlibm_weak_reference(log1p, log1pl);
|
||||
#endif
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
* only tanh(0)=0 is exact for finite argument.
|
||||
*/
|
||||
|
||||
#include <float.h>
|
||||
#include <openlibm_math.h>
|
||||
|
||||
#include "math_private.h"
|
||||
|
@ -76,3 +77,7 @@ tanh(double x)
|
|||
}
|
||||
return (jx>=0)? z: -z;
|
||||
}
|
||||
|
||||
#if (LDBL_MANT_DIG == 53)
|
||||
openlibm_weak_reference(tanh, tanhl);
|
||||
#endif
|
||||
|
|
12
test/test-211.c
Normal file
12
test/test-211.c
Normal file
|
@ -0,0 +1,12 @@
|
|||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <assert.h>
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
float x = 0xd.65874p-4f;
|
||||
float y = 4.0f;
|
||||
float z = powf (x, y);
|
||||
assert(z==0x1.f74424p-2);
|
||||
}
|
Loading…
Add table
Reference in a new issue