MCPcopy Create free account
hub / github.com/RavEngine/RavEngine / SDL_PrintFloat

Function SDL_PrintFloat

deps/SDL2/src/stdlib/SDL_string.c:1542–1643  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1540}
1541
1542static size_t
1543SDL_PrintFloat(char *text, size_t maxlen, SDL_FormatInfo *info, double arg)
1544{
1545 int width;
1546 size_t len;
1547 size_t left = maxlen;
1548 char *textstart = text;
1549
1550 if (arg) {
1551 /* This isn't especially accurate, but hey, it's easy. :) */
1552 unsigned long value;
1553
1554 if (arg < 0) {
1555 if (left > 1) {
1556 *text = '-';
1557 --left;
1558 }
1559 ++text;
1560 arg = -arg;
1561 } else if (info->force_sign) {
1562 if (left > 1) {
1563 *text = '+';
1564 --left;
1565 }
1566 ++text;
1567 }
1568 value = (unsigned long) arg;
1569 len = SDL_PrintUnsignedLong(text, left, NULL, value);
1570 if (len >= left) {
1571 text += (left > 1) ? left - 1 : 0;
1572 left = SDL_min(left, 1);
1573 } else {
1574 text += len;
1575 left -= len;
1576 }
1577 arg -= value;
1578 if (info->precision < 0) {
1579 info->precision = 6;
1580 }
1581 if (info->force_type || info->precision > 0) {
1582 int mult = 10;
1583 if (left > 1) {
1584 *text = '.';
1585 --left;
1586 }
1587 ++text;
1588 while (info->precision-- > 0) {
1589 value = (unsigned long) (arg * mult);
1590 len = SDL_PrintUnsignedLong(text, left, NULL, value);
1591 if (len >= left) {
1592 text += (left > 1) ? left - 1 : 0;
1593 left = SDL_min(left, 1);
1594 } else {
1595 text += len;
1596 left -= len;
1597 }
1598 arg -= (double) value / mult;
1599 mult *= 10;

Callers 1

SDL_vsnprintfFunction · 0.85

Calls 2

SDL_PrintUnsignedLongFunction · 0.85
SDL_memsetFunction · 0.85

Tested by

no test coverage detected