• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

polserver / polserver / 21108840797

18 Jan 2026 08:35AM UTC coverage: 60.508% (+0.02%) from 60.492%
21108840797

push

github

web-flow
ClangTidy readability-else-after-return (#857)

* trigger tidy

* Automated clang-tidy change: readability-else-after-return

* compile test

* rerun

* Automated clang-tidy change: readability-else-after-return

* trigger..

* Automated clang-tidy change: readability-else-after-return

* manually removed a few

* Automated clang-tidy change: readability-else-after-return

* removed duplicate code

* fix remaining warnings

* fixed scope

---------

Co-authored-by: Clang Tidy <clang-tidy@users.noreply.github.com>

837 of 1874 new or added lines in 151 files covered. (44.66%)

46 existing lines in 25 files now uncovered.

44448 of 73458 relevant lines covered (60.51%)

525066.38 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.37
/pol-core/bscript/dbl.cpp
1
/** @file
2
 *
3
 * @par History
4
 */
5

6

7
#include <charconv>
8
#include <cmath>
9
#include <sstream>
10
#include <string>
11
#include <system_error>
12

13
#include "../clib/stlutil.h"
14
#include "berror.h"
15
#include "bobject.h"
16
#include "impstr.h"
17

18

19
namespace Pol::Bscript
20
{
21
std::string Double::double_to_string( double val )
2,003✔
22
{
23
  std::string buff( 100, '\0' );
2,003✔
24
  auto [buffptr, ec] = std::to_chars( buff.data(), buff.data() + buff.size(), val );
2,003✔
25
  if ( ec == std::errc() )
2,003✔
26
  {
27
    buff.resize( buffptr - buff.data() );
2,003✔
28
    return buff;
4,006✔
29
  }
30
  throw std::system_error( std::make_error_code( ec ) );
×
31
}
×
32

33
std::string Double::pack() const
12✔
34
{
35
  return std::string( "r" ) + double_to_string( dval_ );
24✔
36
}
37

38
void Double::packonto( std::ostream& os ) const
6✔
39
{
40
  os << "r" << double_to_string( dval_ );
6✔
41
}
6✔
42

43
BObjectImp* Double::unpack( std::istream& is )
18✔
44
{
45
  double dv;
46
#ifndef __APPLE__
47
  if ( is >> dv )
18✔
48
#else
49
  // well this (and the pack format) is terrible:
50
  // 1) the pack format depends on operator>>(double) magically reading a whole double,
51
  //    but stopping without an error if it's followed by something else
52
  // 2) on osx, operator>>(double) reports an error if the double is followed
53
  //    by something else
54
  // 3) the pack format is ambiguous, mostly, if an error follows a double
55
  // 4) fortunately, nobody will probably ever really run a server on osx
56
  // 5) our options are a bit limited in peeking at an iostream, I think
57
  // so:
58
  //    4.5e-16   a double
59
  //    4.5e+16   a double
60
  //    4.5e62...  a double, followed by an error with 62 elements
61
  //                 - note that technically, this could be a double, but it seems
62
  //                   that the double formatter is being nice and always including - or +
63
  std::string tmp;
64
  tmp.reserve( 16 );
65
  while ( !is.eof() )
66
  {
67
    char ch = is.peek();
68
    if ( std::isdigit( ch ) || ch == '.' || ch == '-' || ch == '+' )
69
    {
70
      tmp.push_back( is.get() );
71
    }
72
    else
73
    {
74
      if ( ch == 'e' )  // might be an exponent, or an error struct following the double (sadface)
75
      {
76
        is.get();  // the 'e'
77

78
        if ( std::isdigit( is.peek() ) )  // assume it's followed by an error struct
79
        {
80
          is.unget();
81
        }
82
        else  // assume it's an exponent
83
        {
84
          tmp.push_back( ch );        // the e
85
          tmp.push_back( is.get() );  // the '+' or '-'
86
          while ( !is.eof() && std::isdigit( is.peek() ) )
87
          {
88
            tmp.push_back( is.get() );
89
          }
90
        }
91
      }
92
      break;
93
    }
94
  }
95
  ISTRINGSTREAM is2( tmp );
96
  if ( is2 >> dv )
97
#endif
98
  {
99
    return new Double( dv );
18✔
100
  }
101

NEW
102
  return new BError( "Error extracting Real value" );
×
103
}
104

105
size_t Double::sizeEstimate() const
134✔
106
{
107
  return sizeof( Double );
134✔
108
}
109

110

111
bool Double::operator==( const BObjectImp& objimp ) const
1,171✔
112
{
113
  if ( objimp.isa( OTDouble ) )
1,171✔
114
  {
115
    double diff = dval_ - ( (Double&)objimp ).dval_;
167✔
116
    return fabs( diff ) < 0.00000001;
167✔
117
  }
118
  if ( objimp.isa( OTLong ) )
1,004✔
119
  {
120
    double diff = dval_ - ( (BLong&)objimp ).value();
989✔
121
    return fabs( diff ) < 0.00000001;
989✔
122
  }
123
  if ( objimp.isa( OTBoolean ) )
15✔
124
  {
125
    return isTrue() == static_cast<const BBoolean&>( objimp ).isTrue();
×
126
  }
127

128
  return false;
15✔
129
}
130

131
bool Double::operator<( const BObjectImp& objimp ) const
291✔
132
{
133
  if ( objimp.isa( OTDouble ) )
291✔
134
  {
135
    return ( dval_ < ( (Double&)objimp ).dval_ );
77✔
136
  }
137
  if ( objimp.isa( OTLong ) )
214✔
138
  {
139
    return ( dval_ < ( (BLong&)objimp ).value() );
202✔
140
  }
141

142
  return base::operator<( objimp );
12✔
143
}
144

145
std::string Double::getStringRep() const
1,970✔
146
{
147
  return double_to_string( dval_ );
1,970✔
148
}
149

150
BObjectImp* Double::selfPlusObjImp( const BObjectImp& objimp ) const
430✔
151
{
152
  return objimp.selfPlusObj( *this );
430✔
153
}
154

155
BObjectImp* Double::selfPlusObj( const BLong& objimp ) const
16✔
156
{
157
  return new Double( dval_ + objimp.value() );
16✔
158
}
159
BObjectImp* Double::selfPlusObj( const Double& objimp ) const
39✔
160
{
161
  return new Double( dval_ + objimp.dval_ );
39✔
162
}
163
BObjectImp* Double::selfPlusObj( const String& objimp ) const
18✔
164
{
165
  return new String( getStringRep() + objimp.value() );
18✔
166
}
167
void Double::selfPlusObjImp( BObjectImp& objimp, BObject& obj )
30✔
168
{
169
  objimp.selfPlusObj( *this, obj );
30✔
170
}
30✔
171
void Double::selfPlusObj( BLong& objimp, BObject& obj )
3✔
172
{
173
  obj.setimp( selfPlusObj( objimp ) );
3✔
174
}
3✔
175
void Double::selfPlusObj( Double& objimp, BObject& /*obj*/ )
3✔
176
{
177
  dval_ += objimp.dval_;
3✔
178
}
3✔
179
void Double::selfPlusObj( String& objimp, BObject& obj )
3✔
180
{
181
  obj.setimp( selfPlusObj( objimp ) );
3✔
182
}
3✔
183

184
BObjectImp* Double::selfMinusObjImp( const BObjectImp& objimp ) const
434✔
185
{
186
  return objimp.selfMinusObj( *this );
434✔
187
}
188
BObjectImp* Double::selfMinusObj( const BLong& objimp ) const
6✔
189
{
190
  return new Double( dval_ - objimp.value() );
6✔
191
}
192
BObjectImp* Double::selfMinusObj( const Double& objimp ) const
397✔
193
{
194
  return new Double( dval_ - objimp.dval_ );
397✔
195
}
196
BObjectImp* Double::selfMinusObj( const String& objimp ) const
15✔
197
{
198
  String s( getStringRep() );
15✔
199
  return s.selfMinusObj( objimp );
30✔
200
}
15✔
201
void Double::selfMinusObjImp( BObjectImp& objimp, BObject& obj )
30✔
202
{
203
  objimp.selfMinusObj( *this, obj );
30✔
204
}
30✔
205
void Double::selfMinusObj( BLong& objimp, BObject& /*obj*/ )
3✔
206
{
207
  dval_ -= objimp.value();
3✔
208
}
3✔
209
void Double::selfMinusObj( Double& objimp, BObject& /*obj*/ )
3✔
210
{
211
  dval_ -= objimp.value();
3✔
212
}
3✔
213
void Double::selfMinusObj( String& objimp, BObject& obj )
3✔
214
{
215
  obj.setimp( selfMinusObj( objimp ) );
3✔
216
}
3✔
217

218
BObjectImp* Double::selfTimesObjImp( const BObjectImp& objimp ) const
51✔
219
{
220
  return objimp.selfTimesObj( *this );
51✔
221
}
222
BObjectImp* Double::selfTimesObj( const BLong& objimp ) const
45✔
223
{
224
  return new Double( dval_ * objimp.value() );
45✔
225
}
226
BObjectImp* Double::selfTimesObj( const Double& objimp ) const
3✔
227
{
228
  return new Double( dval_ * objimp.value() );
3✔
229
}
230
void Double::selfTimesObjImp( BObjectImp& objimp, BObject& obj )
30✔
231
{
232
  objimp.selfTimesObj( *this, obj );
30✔
233
}
30✔
234
void Double::selfTimesObj( BLong& objimp, BObject& /*obj*/ )
3✔
235
{
236
  dval_ *= objimp.value();
3✔
237
}
3✔
238
void Double::selfTimesObj( Double& objimp, BObject& /*obj*/ )
3✔
239
{
240
  dval_ *= objimp.value();
3✔
241
}
3✔
242

243

244
BObjectImp* Double::selfDividedByObjImp( const BObjectImp& objimp ) const
39✔
245
{
246
  return objimp.selfDividedByObj( *this );
39✔
247
}
248
BObjectImp* Double::selfDividedByObj( const BLong& objimp ) const
24✔
249
{
250
  int divisor = objimp.value();
24✔
251
  if ( !divisor )
24✔
252
    return new BError( "Divide by Zero" );
×
253
  return new Double( dval_ / divisor );
24✔
254
}
255
BObjectImp* Double::selfDividedByObj( const Double& objimp ) const
12✔
256
{
257
  double divisor = objimp.value();
12✔
258
  if ( divisor == 0.0 )
12✔
259
    return new BError( "Divide by Zero" );
×
260
  return new Double( dval_ / divisor );
12✔
261
}
262
void Double::selfDividedByObjImp( BObjectImp& objimp, BObject& obj )
30✔
263
{
264
  objimp.selfDividedByObj( *this, obj );
30✔
265
}
30✔
266
void Double::selfDividedByObj( BLong& objimp, BObject& obj )
3✔
267
{
268
  if ( !objimp.value() )
3✔
269
    obj.setimp( new BError( "Divide by Zero" ) );
×
270
  else
271
    dval_ /= objimp.value();
3✔
272
}
3✔
273
void Double::selfDividedByObj( Double& objimp, BObject& obj )
3✔
274
{
275
  if ( !objimp.value() )
3✔
276
    obj.setimp( new BError( "Divide by Zero" ) );
×
277
  else
278
    dval_ /= objimp.value();
3✔
279
}
3✔
280

281
BObjectImp* Double::selfModulusObjImp( const BObjectImp& objimp ) const
114✔
282
{
283
  return objimp.selfModulusObj( *this );
114✔
284
}
285
void Double::selfModulusObjImp( BObjectImp& objimp, BObject& obj )
114✔
286
{
287
  objimp.selfModulusObj( *this, obj );
114✔
288
}
114✔
289
BObjectImp* Double::selfModulusObj( const BLong& objimp ) const
39✔
290
{
291
  if ( !objimp.value() )
39✔
292
    return new BError( "Divide by Zero" );
12✔
293
  return new Double( fmod( dval_, objimp.value() ) );
27✔
294
}
295
BObjectImp* Double::selfModulusObj( const Double& objimp ) const
51✔
296
{
297
  if ( !objimp.value() )
51✔
298
    return new BError( "Divide by Zero" );
12✔
299
  return new Double( fmod( dval_, objimp.value() ) );
39✔
300
}
301
void Double::selfModulusObj( BLong& objimp, BObject& obj )
39✔
302
{
303
  if ( !objimp.value() )
39✔
304
    obj.setimp( new BError( "Divide by Zero" ) );
12✔
305
  else
306
    dval_ = fmod( dval_, objimp.value() );
27✔
307
}
39✔
308
void Double::selfModulusObj( Double& objimp, BObject& obj )
51✔
309
{
310
  if ( !objimp.value() )
51✔
311
    obj.setimp( new BError( "Divide by Zero" ) );
12✔
312
  else
313
    dval_ = fmod( dval_, objimp.value() );
39✔
314
}
51✔
315
}  // namespace Pol::Bscript
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc