OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [gnu-src/] [gdb-6.8/] [libdecnumber/] [decRound.c] - Blame information for rev 221

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 24 jeremybenn
/* Internal testing support for rounding for decimal float.
2
 
3
   Copyright (C) 2005, 2006 Free Software Foundation, Inc.
4
 
5
   This file is part of GCC.
6
 
7
   GCC is free software; you can redistribute it and/or modify it
8
   under the terms of the GNU General Public License as published by
9
   the Free Software Foundation; either version 2, or (at your option)
10
   any later version.
11
 
12
   In addition to the permissions in the GNU General Public License,
13
   the Free Software Foundation gives you unlimited permission to link
14
   the compiled version of this file into combinations with other
15
   programs, and to distribute those combinations without any
16
   restriction coming from the use of this file.  (The General Public
17
   License restrictions do apply in other respects; for example, they
18
   cover modification of the file, and distribution when not linked
19
   into a combine executable.)
20
 
21
   GCC is distributed in the hope that it will be useful, but WITHOUT
22
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
23
   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
24
   License for more details.
25
 
26
   You should have received a copy of the GNU General Public License
27
   along with GCC; see the file COPYING.  If not, write to the Free
28
   Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
29
   02110-1301, USA.  */
30
 
31
#include "config.h"
32
#include "decContext.h"
33
#include "decRound.h"
34
 
35
/* Internal, non-documented functions for testing libgcc functions.
36
   This support is not sufficient for application use.  */
37
 
38
#define FE_DEC_DOWNWARD 0
39
#define FE_DEC_TONEAREST 1
40
#define FE_DEC_TONEARESTFROMZERO 2
41
#define FE_DEC_TOWARDZERO 3
42
#define FE_DEC_UPWARD 4
43
#define FE_DEC_MAX 5
44
 
45
static enum rounding __dfp_rounding_mode = DEC_ROUND_HALF_EVEN;
46
 
47
/* Set the decNumber rounding mode from the FE_DEC_* value in MODE.  */
48
 
49
void
50
__dfp_set_round (int mode)
51
{
52
  switch (mode)
53
    {
54
    case FE_DEC_DOWNWARD:
55
      __dfp_rounding_mode = DEC_ROUND_FLOOR; break;
56
    case FE_DEC_TONEAREST:
57
      __dfp_rounding_mode = DEC_ROUND_HALF_EVEN; break;
58
    case FE_DEC_TONEARESTFROMZERO:
59
      __dfp_rounding_mode = DEC_ROUND_HALF_UP; break;
60
    case FE_DEC_TOWARDZERO:
61
      __dfp_rounding_mode = DEC_ROUND_DOWN; break;
62
    case FE_DEC_UPWARD:
63
      __dfp_rounding_mode = DEC_ROUND_CEILING; break;
64
    default:
65
     /* We can't use assert in libgcc, so just return the default mode.  */
66
      __dfp_rounding_mode = DEC_ROUND_HALF_EVEN; break;
67
    }
68
}
69
 
70
/* Return the decNumber rounding mode as an FE_DEC_* value.  */
71
 
72
int
73
__dfp_get_round (void)
74
{
75
  int mode;
76
 
77
  switch (__dfp_rounding_mode)
78
    {
79
    case DEC_ROUND_FLOOR:
80
      mode = FE_DEC_DOWNWARD; break;
81
    case DEC_ROUND_HALF_EVEN:
82
      mode = FE_DEC_TONEAREST; break;
83
    case DEC_ROUND_HALF_UP:
84
      mode = FE_DEC_TONEARESTFROMZERO; break;
85
    case DEC_ROUND_DOWN:
86
      mode = FE_DEC_TOWARDZERO; break;
87
    case DEC_ROUND_CEILING:
88
      mode = FE_DEC_UPWARD; break;
89
    default:
90
      /* We shouldn't get here, but can't use assert in libgcc.  */
91
      mode = -1;
92
    }
93
  return mode;
94
}
95
 
96
/* Return the decNumber version of the current rounding mode.  */
97
 
98
enum rounding
99
__decGetRound (void)
100
{
101
  return __dfp_rounding_mode;
102
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.