Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Johnston <jjohnstn@redhat.com>2002-08-17 09:57:20 +0400
committerJeff Johnston <jjohnstn@redhat.com>2002-08-17 09:57:20 +0400
commit936b520f8eac458e26623632280b0f34cb8abc17 (patch)
treef4d9c0b7b2bafdca16e643eb2060d48abb5e5315 /newlib/libc/machine/powerpc/strtoufix32.c
parentad5527663ef5d01f531b4d4b23390c7566c93ee2 (diff)
2002-08-17 Jeff Johnston <jjohnstn@redhat.com>
* configure.host: Add powerpc*-*-eabispe* configuration. * libc/machine/powerpc/atosfix16.c: New fixed-point conversion file. * libc/machine/powerpc/atosfix32.c: Ditto. * libc/machine/powerpc/atosfix64.c: Ditto. * libc/machine/powerpc/atoufix16.c: Ditto. * libc/machine/powerpc/atoufix32.c: Ditto. * libc/machine/powerpc/atoufix64.c: Ditto. * libc/machine/powerpc/fix64.h: Ditto. * libc/machine/powerpc/simdldtoa.c: Ditto. * libc/machine/powerpc/strtosfix16.c: Ditto. * libc/machine/powerpc/strtosfix32.c: Ditto. * libc/machine/powerpc/strtosfix64.c: Ditto. * libc/machine/powerpc/strtoufix16.c: Ditto. * libc/machine/powerpc/strtoufix32.c: Ditto. * libc/machine/powerpc/strtoufix64.c: Ditto. * libc/machine/powerpc/ufix64toa.c: Ditto. * libc/machine/powerpc/configure.in: Add check for powerpc*-eabispe and add fixed-point conversion functions. * libc/machine/powerpc/configure: Regenerated. * libc/machine/powerpc/vfprintf.c[__SPE__]: Add support for %r and %R format specifiers which handle fixed-point data. * libc/machine/powerpc/vfscanf.c[__SPE__]: Ditto. * libc/machine/powerpc/machine/stdlib.h[__SPE__]: Add fixed-point function prototypes.
Diffstat (limited to 'newlib/libc/machine/powerpc/strtoufix32.c')
-rw-r--r--newlib/libc/machine/powerpc/strtoufix32.c97
1 files changed, 97 insertions, 0 deletions
diff --git a/newlib/libc/machine/powerpc/strtoufix32.c b/newlib/libc/machine/powerpc/strtoufix32.c
new file mode 100644
index 000000000..141c6278f
--- /dev/null
+++ b/newlib/libc/machine/powerpc/strtoufix32.c
@@ -0,0 +1,97 @@
+#include <_ansi.h>
+#include <limits.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <reent.h>
+#include "vfieeefp.h"
+
+/*
+ * Convert a string to a fixed-point 32-bit value.
+ *
+ * Ignores `locale' stuff.
+ */
+__uint32_t
+_DEFUN (_strtoufix32_r, (rptr, nptr, endptr),
+ struct _reent *rptr _AND
+ _CONST char *nptr _AND
+ char **endptr)
+{
+ union double_union dbl;
+ int exp, negexp, sign;
+ __uint32_t tmp, tmp2, result = 0;
+
+ dbl.d = _strtod_r (rptr, nptr, endptr);
+
+ /* treat NAN as domain error, +/- infinity as saturation */
+ if (!finite(dbl.d))
+ {
+ if (isnan (dbl.d))
+ {
+ rptr->_errno = EDOM;
+ return 0;
+ }
+ rptr->_errno = ERANGE;
+ if (word0(dbl) & Sign_bit)
+ return 0;
+ return ULONG_MAX;
+ }
+
+ /* check for normal saturation */
+ if (dbl.d >= 1.0)
+ {
+ rptr->_errno = ERANGE;
+ return ULONG_MAX;
+ }
+ else if (dbl.d < 0)
+ {
+ rptr->_errno = ERANGE;
+ return 0;
+ }
+
+ /* otherwise we have normal positive number in range */
+
+ /* strip off exponent */
+ exp = ((word0(dbl) & Exp_mask) >> Exp_shift) - Bias;
+ negexp = -exp;
+ if (negexp > 32)
+ return 0;
+ word0(dbl) &= ~(Exp_mask | Sign_bit);
+ /* add in implicit normalized bit */
+ word0(dbl) |= Exp_msk1;
+ /* shift so result is contained left-justified in word */
+ tmp = word0(dbl) << Ebits;
+ tmp |= ((unsigned long)word1(dbl) >> (32 - Ebits));
+ /* perform rounding */
+ if (negexp > 1)
+ {
+ tmp2 = tmp + (1 << (negexp - 2));
+ result = (tmp2 >> (negexp - 1));
+ /* if rounding causes carry, add carry bit in */
+ if (tmp2 < tmp)
+ result += 1 << (32 - negexp);
+ }
+ else
+ {
+ result = tmp + ((word1(dbl) & (1 << (32 - Ebits - 1))) != 0);
+ /* if rounding causes carry, then saturation has occurred */
+ if (result < tmp)
+ {
+ rptr->_errno = ERANGE;
+ return ULONG_MAX;
+ }
+ }
+
+ return result;
+}
+
+#ifndef _REENT_ONLY
+
+__uint32_t
+_DEFUN (strtoufix32, (s, ptr, base),
+ _CONST char *s _AND
+ char **ptr)
+{
+ return _strtoufix32_r (_REENT, s, ptr);
+}
+
+#endif