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

Function CVT_power_of_ten

src/common/cvt.cpp:2544–2592  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2542
2543
2544double CVT_power_of_ten(const int scale)
2545{
2546/*************************************
2547 *
2548 * p o w e r _ o f _ t e n
2549 *
2550 *************************************
2551 *
2552 * Functional description
2553 * return 10.0 raised to the scale power for 0 <= scale < 320.
2554 *
2555 *************************************/
2556
2557 // Note that we could speed things up slightly by making the auxiliary
2558 // arrays global to this source module and replacing this function with
2559 // a macro, but the old code did up to 308 multiplies to our 1, and
2560 // that seems enough of a speed-up for now.
2561
2562 static const double upper_part[] =
2563 {
2564 1.e000, 1.e032, 1.e064, 1.e096, 1.e128,
2565 1.e160, 1.e192, 1.e224, 1.e256, 1.e288
2566 };
2567
2568 static const double lower_part[] =
2569 {
2570 1.e00, 1.e01, 1.e02, 1.e03, 1.e04, 1.e05,
2571 1.e06, 1.e07, 1.e08, 1.e09, 1.e10, 1.e11,
2572 1.e12, 1.e13, 1.e14, 1.e15, 1.e16, 1.e17,
2573 1.e18, 1.e19, 1.e20, 1.e21, 1.e22, 1.e23,
2574 1.e24, 1.e25, 1.e26, 1.e27, 1.e28, 1.e29,
2575 1.e30, 1.e31
2576 };
2577
2578 // The sole caller of this function checks for scale <= 308 before calling,
2579 // but we just fb_assert the weakest precondition which lets the code work.
2580 // If the size of the exponent field, and thus the scaling, of doubles
2581 // gets bigger, increase the size of the upper_part array.
2582
2583 fb_assert((scale >= 0) && (scale < 320));
2584
2585 // Note that "scale >> 5" is another way of writing "scale / 32",
2586 // while "scale & 0x1f" is another way of writing "scale % 32".
2587 // We split the scale into the lower 5 bits and everything else,
2588 // then use the "everything else" to index into the upper_part array,
2589 // whose contents increase in steps of 1e32.
2590
2591 return upper_part[scale >> 5] * lower_part[scale & 0x1f];
2592}
2593
2594
2595static void hex_to_value(const char*& string, const char* end, RetPtr* retValue);

Callers 5

evlPowerFunction · 0.85
CVT_get_longFunction · 0.85
CVT_get_doubleFunction · 0.85
CVT_get_int128Function · 0.85
CVT_get_int64Function · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected