MCPcopy Create free account
hub / github.com/Meituan-Dianping/SQLAdvisor / digits_bounds

Function digits_bounds

strings/decimal.c:457–507  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

455*/
456
457static void digits_bounds(decimal_t *from, int *start_result, int *end_result)
458{
459 int start, stop, i;
460 dec1 *buf_beg= from->buf;
461 dec1 *end= from->buf + ROUND_UP(from->intg) + ROUND_UP(from->frac);
462 dec1 *buf_end= end - 1;
463
464 /* find non-zero digit from number begining */
465 while (buf_beg < end && *buf_beg == 0)
466 buf_beg++;
467
468 if (buf_beg >= end)
469 {
470 /* it is zero */
471 *start_result= *end_result= 0;
472 return;
473 }
474
475 /* find non-zero decimal digit from number begining */
476 if (buf_beg == from->buf && from->intg)
477 {
478 start= DIG_PER_DEC1 - (i= ((from->intg-1) % DIG_PER_DEC1 + 1));
479 i--;
480 }
481 else
482 {
483 i= DIG_PER_DEC1 - 1;
484 start= (int) ((buf_beg - from->buf) * DIG_PER_DEC1);
485 }
486 if (buf_beg < end)
487 for (; *buf_beg < powers10[i--]; start++) ;
488 *start_result= start; /* index of first decimal digit (from 0) */
489
490 /* find non-zero digit at the end */
491 while (buf_end > buf_beg && *buf_end == 0)
492 buf_end--;
493 /* find non-zero decimal digit from the end */
494 if (buf_end == end - 1 && from->frac)
495 {
496 stop= (int) (((buf_end - from->buf) * DIG_PER_DEC1 +
497 (i= ((from->frac - 1) % DIG_PER_DEC1 + 1))));
498 i= DIG_PER_DEC1 - i + 1;
499 }
500 else
501 {
502 stop= (int) ((buf_end - from->buf + 1) * DIG_PER_DEC1);
503 i= 1;
504 }
505 for (; *buf_end % powers10[i++] == 0; stop--) ;
506 *end_result= stop; /* index of position after last decimal digit (from 0) */
507}
508
509
510/*

Callers 1

decimal_shiftFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected