OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-stable/] [gdb-7.2/] [libdecnumber/] [decRound.c] - Blame information for rev 835

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

Line No. Rev Author Line
1 330 jeremybenn
/* Internal testing support for rounding for decimal float.
2
 
3
   Copyright (C) 2005, 2006, 2009 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 3, or (at your option)
10
   any later version.
11
 
12
   GCC is distributed in the hope that it will be useful, but WITHOUT
13
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14
   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
15
   License for more details.
16
 
17
Under Section 7 of GPL version 3, you are granted additional
18
permissions described in the GCC Runtime Library Exception, version
19
3.1, as published by the Free Software Foundation.
20
 
21
You should have received a copy of the GNU General Public License and
22
a copy of the GCC Runtime Library Exception along with this program;
23
see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
24
<http://www.gnu.org/licenses/>.  */
25
 
26
#include "dconfig.h"
27
#include "decContext.h"
28
#include "decRound.h"
29
 
30
/* Internal, non-documented functions for testing libgcc functions.
31
   This support is not sufficient for application use.  */
32
 
33
#define FE_DEC_DOWNWARD 0
34
#define FE_DEC_TONEAREST 1
35
#define FE_DEC_TONEARESTFROMZERO 2
36
#define FE_DEC_TOWARDZERO 3
37
#define FE_DEC_UPWARD 4
38
#define FE_DEC_MAX 5
39
 
40
static enum rounding __dfp_rounding_mode = DEC_ROUND_HALF_EVEN;
41
 
42
/* Set the decNumber rounding mode from the FE_DEC_* value in MODE.  */
43
 
44
void
45
__dfp_set_round (int mode)
46
{
47
  switch (mode)
48
    {
49
    case FE_DEC_DOWNWARD:
50
      __dfp_rounding_mode = DEC_ROUND_FLOOR; break;
51
    case FE_DEC_TONEAREST:
52
      __dfp_rounding_mode = DEC_ROUND_HALF_EVEN; break;
53
    case FE_DEC_TONEARESTFROMZERO:
54
      __dfp_rounding_mode = DEC_ROUND_HALF_UP; break;
55
    case FE_DEC_TOWARDZERO:
56
      __dfp_rounding_mode = DEC_ROUND_DOWN; break;
57
    case FE_DEC_UPWARD:
58
      __dfp_rounding_mode = DEC_ROUND_CEILING; break;
59
    default:
60
     /* We can't use assert in libgcc, so just return the default mode.  */
61
      __dfp_rounding_mode = DEC_ROUND_HALF_EVEN; break;
62
    }
63
}
64
 
65
/* Return the decNumber rounding mode as an FE_DEC_* value.  */
66
 
67
int
68
__dfp_get_round (void)
69
{
70
  int mode;
71
 
72
  switch (__dfp_rounding_mode)
73
    {
74
    case DEC_ROUND_FLOOR:
75
      mode = FE_DEC_DOWNWARD; break;
76
    case DEC_ROUND_HALF_EVEN:
77
      mode = FE_DEC_TONEAREST; break;
78
    case DEC_ROUND_HALF_UP:
79
      mode = FE_DEC_TONEARESTFROMZERO; break;
80
    case DEC_ROUND_DOWN:
81
      mode = FE_DEC_TOWARDZERO; break;
82
    case DEC_ROUND_CEILING:
83
      mode = FE_DEC_UPWARD; break;
84
    default:
85
      /* We shouldn't get here, but can't use assert in libgcc.  */
86
      mode = -1;
87
    }
88
  return mode;
89
}
90
 
91
/* Return the decNumber version of the current rounding mode.  */
92
 
93
enum rounding
94
__decGetRound (void)
95
{
96
  return __dfp_rounding_mode;
97
}

powered by: WebSVN 2.1.0

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