MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / compare

Method compare

extern/boost/boost/multiprecision/cpp_dec_float.hpp:1381–1459  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1379
1380template <unsigned Digits10, class ExponentType, class Allocator>
1381int cpp_dec_float<Digits10, ExponentType, Allocator>::compare(const cpp_dec_float& v) const
1382{
1383 // Compare v with *this.
1384 // Return +1 for *this > v
1385 // 0 for *this = v
1386 // -1 for *this < v
1387
1388 // Handle all non-finite cases.
1389 if ((!(isfinite)()) || (!(v.isfinite)()))
1390 {
1391 // NaN can never equal NaN. Return an implementation-dependent
1392 // signed result. Also note that comparison of NaN with NaN
1393 // using operators greater-than or less-than is undefined.
1394 if ((isnan)() || (v.isnan)())
1395 {
1396 return ((isnan)() ? 1 : -1);
1397 }
1398
1399 if ((isinf)() && (v.isinf)())
1400 {
1401 // Both *this and v are infinite. They are equal if they have the same sign.
1402 // Otherwise, *this is less than v if and only if *this is negative.
1403 return ((neg == v.neg) ? 0 : (neg ? -1 : 1));
1404 }
1405
1406 if ((isinf)())
1407 {
1408 // *this is infinite, but v is finite.
1409 // So negative infinite *this is less than any finite v.
1410 // Whereas positive infinite *this is greater than any finite v.
1411 return (isneg() ? -1 : 1);
1412 }
1413 else
1414 {
1415 // *this is finite, and v is infinite.
1416 // So any finite *this is greater than negative infinite v.
1417 // Whereas any finite *this is less than positive infinite v.
1418 return (v.neg ? 1 : -1);
1419 }
1420 }
1421
1422 // And now handle all *finite* cases.
1423 if (iszero())
1424 {
1425 // The value of *this is zero and v is either zero or non-zero.
1426 return (v.iszero() ? 0
1427 : (v.neg ? 1 : -1));
1428 }
1429 else if (v.iszero())
1430 {
1431 // The value of v is zero and *this is non-zero.
1432 return (neg ? -1 : 1);
1433 }
1434 else
1435 {
1436 // Both *this and v are non-zero.
1437
1438 if (neg != v.neg)

Callers 15

compareFunction · 0.45
type compareMethod · 0.45
extract_doubleMethod · 0.45
extract_long_doubleMethod · 0.45
rd_stringMethod · 0.45
eval_is_zeroFunction · 0.45
eval_get_signFunction · 0.45
eval_absFunction · 0.45
eval_fabsFunction · 0.45

Calls 2

iszeroMethod · 0.80
cbeginMethod · 0.45

Tested by

no test coverage detected