static void print4 (char *buffer, double value, int iformat, int width, int precision) { char formatString [40]; if (iformat == 4) { long numerator, denominator; NUMrationalize (value, & numerator, & denominator); if (numerator == 0) snprintf (buffer, 40, "0"); else if (denominator > 1) snprintf (buffer, 40, "%ld/%ld", numerator, denominator); else snprintf (buffer, 40, "%.7g", value); } else { snprintf (formatString, 40, "%%%d.%d%c", width, precision, iformat == 1 ? 'f' : iformat == 2 ? 'e' : 'g'); snprintf (buffer, 40, formatString, value); } }
static void print4 (wchar_t *buffer, double value, int iformat, int width, int precision) { wchar_t formatString [40]; if (value == NUMundefined) wcscpy (buffer, L"undefined"); else if (iformat == 4) { long numerator, denominator; NUMrationalize (value, & numerator, & denominator); if (numerator == 0) swprintf (buffer, 40, L"0"); else if (denominator > 1) swprintf (buffer, 40, L"%ld/%ld", numerator, denominator); else swprintf (buffer, 40, L"%.7g", value); } else { swprintf (formatString, 40, L"%%%d.%d%c", width, precision, iformat == 1 ? 'f' : iformat == 2 ? 'e' : 'g'); swprintf (buffer, 40, formatString, value); } }