MCPcopy Create free account
hub / github.com/coreutils/coreutils / simple_round

Function simple_round

src/numfmt.c:420–455  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

418
419ATTRIBUTE_CONST
420static inline long double
421simple_round (long double val, enum round_type t)
422{
423 intmax_t rval;
424 intmax_t intmax_mul = val / INTMAX_MAX;
425 val -= (long double) INTMAX_MAX * intmax_mul;
426
427 switch (t)
428 {
429 case round_ceiling:
430 rval = simple_round_ceiling (val);
431 break;
432
433 case round_floor:
434 rval = simple_round_floor (val);
435 break;
436
437 case round_from_zero:
438 rval = simple_round_from_zero (val);
439 break;
440
441 case round_to_zero:
442 rval = simple_round_to_zero (val);
443 break;
444
445 case round_nearest:
446 rval = simple_round_nearest (val);
447 break;
448
449 default:
450 /* to silence the compiler - this should never happen. */
451 return 0;
452 }
453
454 return (long double) INTMAX_MAX * intmax_mul + rval;
455}
456
457enum simple_strtod_error
458{

Callers 1

double_to_humanFunction · 0.85

Calls 5

simple_round_ceilingFunction · 0.85
simple_round_floorFunction · 0.85
simple_round_from_zeroFunction · 0.85
simple_round_to_zeroFunction · 0.85
simple_round_nearestFunction · 0.85

Tested by

no test coverage detected