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

polserver / polserver / 25918451630

15 May 2026 12:43PM UTC coverage: 60.929% (+2.1%) from 58.859%
25918451630

push

github

turleypol
added dynamic property which returns a pointer of the object instead of
a copy like the current imp.
needed to be able to eg store a vector

43 of 61 new or added lines in 2 files covered. (70.49%)

14455 existing lines in 345 files now uncovered.

44695 of 73356 relevant lines covered (60.93%)

449621.59 hits per line

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

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

6

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

14
#include <fmt/compile.h>
15

16
#include "../clib/stlutil.h"
17
#include "berror.h"
18
#include "bobject.h"
19
#include "impstr.h"
20

21

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

36
void Double::packonto( std::string& str ) const
18✔
37
{
38
  using namespace fmt::literals;
39
  fmt::format_to( std::back_inserter( str ), "r{}"_cf, double_to_string( dval_ ) );
18✔
40
}
18✔
41

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

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

UNCOV
101
  return new BError( "Error extracting Real value" );
×
102
}
103

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

109

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

127
  return false;
15✔
128
}
129

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

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

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

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

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

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

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

242

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

280
BObjectImp* Double::selfModulusObjImp( const BObjectImp& objimp ) const
114✔
281
{
282
  return objimp.selfModulusObj( *this );
114✔
283
}
284
void Double::selfModulusObjImp( BObjectImp& objimp, BObject& obj )
114✔
285
{
286
  objimp.selfModulusObj( *this, obj );
114✔
287
}
114✔
288
BObjectImp* Double::selfModulusObj( const BLong& objimp ) const
39✔
289
{
290
  if ( !objimp.value() )
39✔
291
    return new BError( "Divide by Zero" );
12✔
292
  return new Double( fmod( dval_, objimp.value() ) );
27✔
293
}
294
BObjectImp* Double::selfModulusObj( const Double& objimp ) const
51✔
295
{
296
  if ( !objimp.value() )
51✔
297
    return new BError( "Divide by Zero" );
12✔
298
  return new Double( fmod( dval_, objimp.value() ) );
39✔
299
}
300
void Double::selfModulusObj( BLong& objimp, BObject& obj )
39✔
301
{
302
  if ( !objimp.value() )
39✔
303
    obj.setimp( new BError( "Divide by Zero" ) );
12✔
304
  else
305
    dval_ = fmod( dval_, objimp.value() );
27✔
306
}
39✔
307
void Double::selfModulusObj( Double& objimp, BObject& obj )
51✔
308
{
309
  if ( !objimp.value() )
51✔
310
    obj.setimp( new BError( "Divide by Zero" ) );
12✔
311
  else
312
    dval_ = fmod( dval_, objimp.value() );
39✔
313
}
51✔
314
}  // 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