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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.5.1/] [libstdc++-v3/] [testsuite/] [21_strings/] [basic_string/] [numeric_conversions/] [char/] [stod.cc] - Blame information for rev 424

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 424 jeremybenn
// { dg-options "-std=gnu++0x" }
2
// { dg-require-string-conversions "" }
3
 
4
// 2008-06-15  Paolo Carlini  <paolo.carlini@oracle.com>
5
 
6
// Copyright (C) 2008, 2009 Free Software Foundation, Inc.
7
//
8
// This file is part of the GNU ISO C++ Library.  This library is free
9
// software; you can redistribute it and/or modify it under the
10
// terms of the GNU General Public License as published by the
11
// Free Software Foundation; either version 3, or (at your option)
12
// any later version.
13
 
14
// This library is distributed in the hope that it will be useful,
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
// GNU General Public License for more details.
18
 
19
// You should have received a copy of the GNU General Public License along
20
// with this library; see the file COPYING3.  If not see
21
// <http://www.gnu.org/licenses/>.
22
 
23
// 21.4 Numeric Conversions [string.conversions]
24
 
25
#include <string>
26
#include <limits>
27
#include <stdexcept>
28
#include <testsuite_hooks.h>
29
 
30
void
31
test01()
32
{
33
  bool test __attribute__((unused)) = false;
34
  using namespace std;
35
 
36
  try
37
    {
38
      string one;
39
      stod(one);
40
    }
41
  catch(std::invalid_argument)
42
    {
43
      test = true;
44
    }
45
  catch(...)
46
    {
47
    }
48
  VERIFY( test );
49
 
50
  test = false;
51
  try
52
    {
53
      string one("a");
54
      stod(one);
55
    }
56
  catch(std::invalid_argument)
57
    {
58
      test = true;
59
    }
60
  catch(...)
61
    {
62
    }
63
  VERIFY( test );
64
 
65
  double d1 = 0.0;
66
  size_t idx1 = 0;
67
  try
68
    {
69
      string one("2.0a");
70
      d1 = stod(one, &idx1);
71
    }
72
  catch(...)
73
    {
74
      test = false;
75
    }
76
  VERIFY( test );
77
  VERIFY( d1 == 2.0 );
78
  VERIFY( idx1 == 3 );
79
 
80
  test = false;
81
  try
82
    {
83
      string one("1e");
84
      one.append(2 * numeric_limits<double>::max_exponent10, '9');
85
      d1 = stod(one);
86
    }
87
  catch(std::out_of_range)
88
    {
89
      test = true;
90
    }
91
  catch(...)
92
    {
93
    }
94
  VERIFY( test );
95
  VERIFY( d1 == 2.0 );
96
 
97
  try
98
    {
99
      long double ld0 = numeric_limits<double>::max() / 100.0;
100
      string one(to_string(ld0));
101
      stod(one);
102
    }
103
  catch(...)
104
    {
105
      test = false;
106
    }
107
  VERIFY( test );
108
 
109
  if ((numeric_limits<long double>::max() / 10000.0L)
110
      > numeric_limits<double>::max())
111
    {
112
      test = false;
113
      d1 = -1.0;
114
      try
115
        {
116
          long double ld1 = numeric_limits<double>::max();
117
          ld1 *= 100.0;
118
          string one(to_string(ld1));
119
          d1 = stod(one);
120
        }
121
      catch(std::out_of_range)
122
        {
123
          test = true;
124
        }
125
      catch(...)
126
        {
127
        }
128
      VERIFY( test );
129
      VERIFY( d1 == -1.0 );
130
    }
131
}
132
 
133
int main()
134
{
135
  test01();
136
  return 0;
137
}

powered by: WebSVN 2.1.0

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