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

__adjust.c « stdlib « libc « newlib - cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d5c70758b1f4330a28e56fd6b25a6e11c97d02b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
 * return (*acc) scaled by 10**dexp.
 */

#include <_ansi.h>
#include <reent.h>
#include "std.h"

#define abs(x) (((x) < 0) ? -(x) : (x))

double
_DEFUN (__adjust, (ptr, acc, dexp, sign),
	struct _reent *ptr _AND
	double *acc _AND
	int dexp _AND
	int sign)
     /* *acc	the 64 bit accumulator */
     /* dexp	decimal exponent       */
     /* sign	sign flag   	       */
{
  double r;

  if (dexp > MAXE)
    {
      ptr->_errno = ERANGE;
      return (sign) ? -HUGE_VAL : HUGE_VAL;
    }
  else if (dexp < MINE)
    {
      ptr->_errno = ERANGE;
      return 0.0;
    }

  r = *acc;
  if (sign)
    r = -r;
  if (dexp == 0)
    return r;

  if (dexp < 0)
    return r / __exp10 (abs (dexp));
  else
    return r * __exp10 (dexp);
}