Skip to content
Myr

rename all stb_sprintf identifiers to follow stb conventions

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Sean Barrett · committed by Sean Barrett · parent fd23d70 · Browse files · 6 files+338 added−303 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

6 files+338 added−303 removed

  • tests:+23 added−0 removed
  • other:+315 added−303 removed

6 files+338 added−303 removed

modified:tests/grid_reachability.c+3 added
141 unmodified lines
142 tm = (end.QuadPart - start.QuadPart) / (double) freq.QuadPart;143 printf("%6.4lf ms: %s\n", tm * 1000, message);144}145146extern void quicktest(void);147148int loc[5000][2];149int main(int argc, char **argv)150{151 stbcc_grid *g;
1 unmodified line
153 int w,h, i,j,k=0, count=0, r;154 uint8 *map = stbi_load("data/map_03.png", &w, &h, 0, 1);155156 assert(map);157 quicktest();158159 for (j=0; j < h; ++j)160 for (i=0; i < w; ++i)161 map[j*w+i] = ~map[j*w+i];
202 unmodified lines
modified:tests/stb.dsp+4 added
152 unmodified lines
153SOURCE=..\stb_rect_pack.h154# End Source File155# Begin Source File156157SOURCE=..\stb_sprintf.h158# End Source File159# Begin Source File160161SOURCE=..\stb_textedit.h162# End Source File163# Begin Source File164
40 unmodified lines
modified:tests/test_c_compilation.c+12 added
1#include "stb_sprintf.h"2#define STB_SPRINTF_IMPLEMENTATION3#include "stb_sprintf.h"45#define STB_PERLIN_IMPLEMENTATION6#define STB_IMAGE_WRITE_IMPLEMENTATION7#define STB_DXT_IMPLEMENATION8#define STB_C_LEXER_IMPLEMENTATIOn
22 unmodified lines
31#define STBTE_DRAW_RECT(x0,y0,x1,y1,color) 032#define STBTE_DRAW_TILE(x,y,id,highlight,data) 033#define STB_TILEMAP_EDITOR_IMPLEMENTATION34#include "stb_tilemap_editor.h"353637int quicktest(void)38{39 char buffer[999];40 stbsp_sprintf(buffer, "test%%test");41 return 0;42}
modified:tests/test_cpp_compilation.cpp+4 added
1#include "stb_sprintf.h"2#define STB_SPRINTF_IMPLEMENTATION3#include "stb_sprintf.h"45#define STB_TRUETYPE_IMPLEMENTATION6#define STB_PERLIN_IMPLEMENTATION7#define STB_IMAGE_WRITE_IMPLEMENTATION8#define STB_DXT_IMPLEMENATION
138 unmodified lines
modified:stb_sprintf.h+314 added-303 removed
1#ifndef RR_SPRINTF_H_INCLUDE2#define RR_SPRINTF_H_INCLUDE1// stb_sprintf - v1.00 - public domain snprintf() implementation2// originally by Jeff Roberts / RAD Game Tools, 2015/10/203// http://github.com/nothings/stb4//5// allowed types: sc uidBboXx p AaGgEef n6// lengths : h ll j z t I64 I32 I78910#ifndef STB_SPRINTF_H_INCLUDE11#define STB_SPRINTF_H_INCLUDE1213/*14Single file sprintf replacement.1516Originally written by Jeff Roberts at RAD Game Tools - 2015/10/20.
13 unmodified lines
3031It uses the standard single file trick of being both the header file32and the source itself. If you just include it normally, you just get 33the header file function definitions. To get the code, you include25it from a C or C++ file and define RR_SPRINTF_IMPLEMENTATION first.34it from a C or C++ file and define STB_SPRINTF_IMPLEMENTATION first.3536It only uses va_args macros from the C runtime to do it's work. It37does cast doubles to S64s and shifts and divides U64s, which does 38drag in CRT code on most platforms.
3 unmodified lines
42in 16K.4344API:45====37int rrsprintf( char * buf, char const * fmt, ... )38int rrsnprintf( char * buf, int count, char const * fmt, ... )46int stbsp_sprintf( char * buf, char const * fmt, ... )47int stbsp_snprintf( char * buf, int count, char const * fmt, ... )48 Convert an arg list into a buffer. rrsnprintf always returns49 a zero-terminated string (unlike regular snprintf).5042int rrvsprintf( char * buf, char const * fmt, va_list va )43int rrvsnprintf( char * buf, int count, char const * fmt, va_list va )51int stbsp_vsprintf( char * buf, char const * fmt, va_list va )52int stbsp_vsnprintf( char * buf, int count, char const * fmt, va_list va )53 Convert a va_list arg list into a buffer. rrvsnprintf always returns54 a zero-terminated string (unlike regular snprintf).5547int rrvsprintfcb( RRSPRINTFCB * callback, void * user, char * buf, char const * fmt, va_list va )48 typedef char * RRSPRINTFCB( char const * buf, void * user, int len );49 Convert into a buffer, calling back every RR_SPRINTF_MIN chars.56int stbsp_vsprintfcb( STBSP_SPRINTFCB * callback, void * user, char * buf, char const * fmt, va_list va )57 typedef char * STBSP_SPRINTFCB( char const * buf, void * user, int len );58 Convert into a buffer, calling back every STB_SPRINTF_MIN chars.59 Your callback can then copy the chars out, print them or whatever.60 This function is actually the workhorse for everything else.52 The buffer you pass in must hold at least RR_SPRINTF_MIN characters.61 The buffer you pass in must hold at least STB_SPRINTF_MIN characters.62 // you return the next buffer to use or 0 to stop converting6355void rrsetseparators( char comma, char period )64void stbsp_set_seperators( char comma, char period )65 Set the comma and period characters to use.6667FLOATS/DOUBLES:68===============
6 unmodified lines
75with MSVC or GCC (but they don't match each other either). We also 76don't attempt to find the minimum length matching float (pre-MSVC15 77doesn't either).7870If you don't need float or doubles at all, define RR_SPRINTF_NOFLOAT79If you don't need float or doubles at all, define STB_SPRINTF_NOFLOAT80and you'll save 4K of code space.817364-BIT INTS:8264-STBSP__INTMAXT INTS:83============84This library also supports 64-bit integers and you can use MSVC style or85GCC style indicators (%I64d or %lld). It supports the C99 specifiers86for size_t and ptr_diff_t (%jd %zd) as well.
32 unmodified lines
119"%s%s%s" for 64 char strings (7.1x/7.3x faster)120"...512 char string..." ( 35.0x/32.5x faster!)121*/122114#ifdef RR_SPRINTF_STATIC115#define RRPUBLIC_DEC static116#define RRPUBLIC_DEF static123#ifdef STB_SPRINTF_STATIC124#define STBSP__PUBLICDEC static125#define STBSP__PUBLICDEF static126#else127#ifdef __cplusplus119#define RRPUBLIC_DEC extern "C"120#define RRPUBLIC_DEF extern "C"128#define STBSP__PUBLICDEC extern "C"129#define STBSP__PUBLICDEF extern "C"130#else122#define RRPUBLIC_DEC extern 123#define RRPUBLIC_DEF131#define STBSP__PUBLICDEC extern 132#define STBSP__PUBLICDEF133#endif134#endif135136#include <stdarg.h> // for va_list()137129#ifndef RR_SPRINTF_MIN130#define RR_SPRINTF_MIN 512 // how many characters per callback138#ifndef STB_SPRINTF_MIN139#define STB_SPRINTF_MIN 512 // how many characters per callback140#endif132typedef char * RRSPRINTFCB( char * buf, void * user, int len );141typedef char * STBSP_SPRINTFCB( char * buf, void * user, int len );142134#ifndef RR_SPRINTF_DECORATE135#define RR_SPRINTF_DECORATE(name) rr##name // define this before including if you want to change the names143#ifndef STB_SPRINTF_DECORATE144#define STB_SPRINTF_DECORATE(name) stbsp_##name // define this before including if you want to change the names145#endif146138#ifndef RR_SPRINTF_IMPLEMENTATION147STBSP__PUBLICDEF int STB_SPRINTF_DECORATE( vsprintf )( char * buf, char const * fmt, va_list va );148STBSP__PUBLICDEF int STB_SPRINTF_DECORATE( vsnprintf )( char * buf, int count, char const * fmt, va_list va );149STBSP__PUBLICDEF int STB_SPRINTF_DECORATE( sprintf ) ( char * buf, char const * fmt, ... );150STBSP__PUBLICDEF int STB_SPRINTF_DECORATE( snprintf )( char * buf, int count, char const * fmt, ... );151140RRPUBLIC_DEF int RR_SPRINTF_DECORATE( vsprintf )( char * buf, char const * fmt, va_list va );141RRPUBLIC_DEF int RR_SPRINTF_DECORATE( vsnprintf )( char * buf, int count, char const * fmt, va_list va );142RRPUBLIC_DEF int RR_SPRINTF_DECORATE( sprintf ) ( char * buf, char const * fmt, ... );143RRPUBLIC_DEF int RR_SPRINTF_DECORATE( snprintf )( char * buf, int count, char const * fmt, ... );152STBSP__PUBLICDEF int STB_SPRINTF_DECORATE( vsprintfcb )( STBSP_SPRINTFCB * callback, void * user, char * buf, char const * fmt, va_list va );153STBSP__PUBLICDEF void STB_SPRINTF_DECORATE( set_separators )( char comma, char period );154145RRPUBLIC_DEF int RR_SPRINTF_DECORATE( vsprintfcb )( RRSPRINTFCB * callback, void * user, char * buf, char const * fmt, va_list va );146RRPUBLIC_DEF void RR_SPRINTF_DECORATE( setseparators )( char comma, char period );155#endif // STB_SPRINTF_H_INCLUDE156148#else157#ifndef STB_SPRINTF_IMPLEMENTATION158159#include <stdlib.h> // for va_arg()160152#define rU32 unsigned int153#define rS32 signed int161#define stbsp__uint32 unsigned int162#define stbsp__int32 signed int163164#ifdef _MSC_VER156#define rU64 unsigned __int64157#define rS64 signed __int64165#define stbsp__uint64 unsigned __int64166#define stbsp__int64 signed __int64167#else159#define rU64 unsigned long long160#define rS64 signed long long168#define stbsp__uint64 unsigned long long169#define stbsp__int64 signed long long170#endif162#define rU16 unsigned short171#define stbsp__uint16 unsigned short172164#ifndef rUINTa 173#ifndef stbsp__uintptr 174#if defined(__ppc64__) || defined(__aarch64__) || defined(_M_X64) || defined(__x86_64__) || defined(__x86_64)166#define rUINTa rU64175#define stbsp__uintptr stbsp__uint64176#else168#define rUINTa rU32177#define stbsp__uintptr stbsp__uint32178#endif179#endif180172#ifndef RR_SPRINTF_MSVC_MODE // used for MSVC2013 and earlier (MSVC2015 matches GCC)181#ifndef STB_SPRINTF_MSVC_MODE // used for MSVC2013 and earlier (MSVC2015 matches GCC)182#if defined(_MSC_VER) && (_MSC_VER<1900)174#define RR_SPRINTF_MSVC_MODE183#define STB_SPRINTF_MSVC_MODE184#endif185#endif186178#ifdef RR_SPRINTF_NOUNALIGNED // define this before inclusion to force rrsprint to always use aligned accesses179#define RR_UNALIGNED(code)187#ifdef STB_SPRINTF_NOUNALIGNED // define this before inclusion to force rrsprint to always use aligned accesses188#define STBSP__UNALIGNED(code)189#else181#define RR_UNALIGNED(code) code190#define STBSP__UNALIGNED(code) code191#endif192184#ifndef RR_SPRINTF_NOFLOAT193#ifndef STB_SPRINTF_NOFLOAT194// internal float utility functions186static rS32 rrreal_to_str( char const * * start, rU32 * len, char *out, rS32 * decimal_pos, double value, rU32 frac_digits );187static rS32 rrreal_to_parts( rS64 * bits, rS32 * expo, double value );188#define RRSPECIAL 0x7000195static stbsp__int32 stbsp__real_to_str( char const * * start, stbsp__uint32 * len, char *out, stbsp__int32 * decimal_pos, double value, stbsp__uint32 frac_digits );196static stbsp__int32 stbsp__real_to_parts( stbsp__int64 * bits, stbsp__int32 * expo, double value );197#define STBSP__SPECIAL 0x7000198#endif199191static char RRperiod='.';192static char RRcomma=',';193static char rrdiglookup[201]="00010203040506070809101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899";200static char stbsp__period='.';201static char stbsp__comma=',';202static char stbsp__digitpair[201]="00010203040506070809101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899";203195RRPUBLIC_DEF void RR_SPRINTF_DECORATE( setseparators )( char pcomma, char pperiod )204STBSP__PUBLICDEF void STB_SPRINTF_DECORATE( set_separators )( char pcomma, char pperiod )205{197 RRperiod=pperiod;198 RRcomma=pcomma;206 stbsp__period=pperiod;207 stbsp__comma=pcomma;208}209201RRPUBLIC_DEF int RR_SPRINTF_DECORATE( vsprintfcb )( RRSPRINTFCB * callback, void * user, char * buf, char const * fmt, va_list va )210STBSP__PUBLICDEF int STB_SPRINTF_DECORATE( vsprintfcb )( STBSP_SPRINTFCB * callback, void * user, char * buf, char const * fmt, va_list va )211{212 static char hex[]="0123456789abcdefxp";213 static char hexu[]="0123456789ABCDEFXP";214 char * bf;
3 unmodified lines
218 bf = buf;219 f = fmt;220 for(;;)221 {213 rS32 fw,pr,tz; rU32 fl;222 stbsp__int32 fw,pr,tz; stbsp__uint32 fl;223215 #define LJ 1216 #define LP 2217 #define LS 4218 #define LX 8219 #define LZ 16220 #define BI 32221 #define CS 64222 #define NG 128223 #define KI 256224 #define HW 512224 #define STBSP__LEFTJUST 1225 #define STBSP__LEADINGPLUS 2226 #define STBSP__LEADINGSPACE 4227 #define STBSP__LEADING_0X 8228 #define STBSP__LEADINGZERO 16229 #define STBSP__INTMAX 32230 #define STBSP__TRIPLET_COMMA 64231 #define STBSP__NEGATIVE 128232 #define STBSP__METRIC_SUFFIX 256233 #define STBSP__HALFWIDTH 512234 235 // macros for the callback buffer stuff227 #define chk_cb_bufL(bytes) { int len = (int)(bf-buf); if ((len+(bytes))>=RR_SPRINTF_MIN) { tlen+=len; if (0==(bf=buf=callback(buf,user,len))) goto done; } }228 #define chk_cb_buf(bytes) { if ( callback ) { chk_cb_bufL(bytes); } }229 #define flush_cb() { chk_cb_bufL(RR_SPRINTF_MIN-1); } //flush if there is even one byte in the buffer230 #define cb_buf_clamp(cl,v) cl = v; if ( callback ) { int lg = RR_SPRINTF_MIN-(int)(bf-buf); if (cl>lg) cl=lg; }236 #define stbsp__chk_cb_bufL(bytes) { int len = (int)(bf-buf); if ((len+(bytes))>=STB_SPRINTF_MIN) { tlen+=len; if (0==(bf=buf=callback(buf,user,len))) goto done; } }237 #define stbsp__chk_cb_buf(bytes) { if ( callback ) { stbsp__chk_cb_bufL(bytes); } }238 #define stbsp__flush_cb() { stbsp__chk_cb_bufL(STB_SPRINTF_MIN-1); } //flush if there is even one byte in the buffer239 #define stbsp__cb_buf_clamp(cl,v) cl = v; if ( callback ) { int lg = STB_SPRINTF_MIN-(int)(bf-buf); if (cl>lg) cl=lg; }240241 // fast copy everything up to the next % (or end of string)242 for(;;)243 { 235 while (((rUINTa)f)&3)244 while (((stbsp__uintptr)f)&3)245 {246 schk1: if (f[0]=='%') goto scandd;247 schk2: if (f[0]==0) goto endfmt;239 chk_cb_buf(1); *bf++=f[0]; ++f;248 stbsp__chk_cb_buf(1); *bf++=f[0]; ++f;249 } 250 for(;;)251 { 243 rU32 v,c;244 v=*(rU32*)f; c=(~v)&0x80808080;252 stbsp__uint32 v,c;253 v=*(stbsp__uint32*)f; c=(~v)&0x80808080;254 if ((v-0x26262626)&c) goto schk1; 255 if ((v-0x01010101)&c) goto schk2; 247 if (callback) if ((RR_SPRINTF_MIN-(int)(bf-buf))<4) goto schk1;248 *(rU32*)bf=v; bf+=4; f+=4;256 if (callback) if ((STB_SPRINTF_MIN-(int)(bf-buf))<4) goto schk1;257 *(stbsp__uint32*)bf=v; bf+=4; f+=4;258 }259 } scandd:260261 ++f;
5 unmodified lines
267 for(;;)268 {269 switch(f[0])270 {262 // if we have left just263 case '-': fl|=LJ; ++f; continue;271 // if we have left justify272 case '-': fl|=STBSP__LEFTJUST; ++f; continue;273 // if we have leading plus265 case '+': fl|=LP; ++f; continue; 274 case '+': fl|=STBSP__LEADINGPLUS; ++f; continue; 275 // if we have leading space267 case ' ': fl|=LS; ++f; continue; 276 case ' ': fl|=STBSP__LEADINGSPACE; ++f; continue; 277 // if we have leading 0x269 case '#': fl|=LX; ++f; continue; 278 case '#': fl|=STBSP__LEADING_0X; ++f; continue; 279 // if we have thousand commas271 case '\'': fl|=CS; ++f; continue; 280 case '\'': fl|=STBSP__TRIPLET_COMMA; ++f; continue; 281 // if we have kilo marker273 case '$': fl|=KI; ++f; continue; 282 case '$': fl|=STBSP__METRIC_SUFFIX; ++f; continue; 283 // if we have leading zero275 case '0': fl|=LZ; ++f; goto flags_done; 284 case '0': fl|=STBSP__LEADINGZERO; ++f; goto flags_done; 285 default: goto flags_done;286 }287 }288 flags_done:289 290 // get the field width282 if ( f[0] == '*' ) {fw = va_arg(va,rU32); ++f;} else { while (( f[0] >= '0' ) && ( f[0] <= '9' )) { fw = fw * 10 + f[0] - '0'; f++; } }291 if ( f[0] == '*' ) {fw = va_arg(va,stbsp__uint32); ++f;} else { while (( f[0] >= '0' ) && ( f[0] <= '9' )) { fw = fw * 10 + f[0] - '0'; f++; } }292 // get the precision284 if ( f[0]=='.' ) { ++f; if ( f[0] == '*' ) {pr = va_arg(va,rU32); ++f;} else { pr = 0; while (( f[0] >= '0' ) && ( f[0] <= '9' )) { pr = pr * 10 + f[0] - '0'; f++; } } } 293 if ( f[0]=='.' ) { ++f; if ( f[0] == '*' ) {pr = va_arg(va,stbsp__uint32); ++f;} else { pr = 0; while (( f[0] >= '0' ) && ( f[0] <= '9' )) { pr = pr * 10 + f[0] - '0'; f++; } } } 294 295 // handle integer size overrides296 switch(f[0])297 {298 // are we halfwidth?290 case 'h': fl|=HW; ++f; break;299 case 'h': fl|=STBSP__HALFWIDTH; ++f; break;300 // are we 64-bit (unix style)292 case 'l': ++f; if ( f[0]=='l') { fl|=BI; ++f; } break;301 case 'l': ++f; if ( f[0]=='l') { fl|=STBSP__INTMAX; ++f; } break;302 // are we 64-bit on intmax? (c99)294 case 'j': fl|=BI; ++f; break; 303 case 'j': fl|=STBSP__INTMAX; ++f; break; 304 // are we 64-bit on size_t or ptrdiff_t? (c99)296 case 'z': case 't': fl|=((sizeof(char*)==8)?BI:0); ++f; break; 305 case 'z': case 't': fl|=((sizeof(char*)==8)?STBSP__INTMAX:0); ++f; break; 306 // are we 64-bit (msft style)298 case 'I': if ( ( f[1]=='6') && ( f[2]=='4') ) { fl|=BI; f+=3; } else if ( ( f[1]=='3') && ( f[2]=='2') ) { f+=3; } else { fl|=((sizeof(void*)==8)?BI:0); ++f; } break;307 case 'I': if ( ( f[1]=='6') && ( f[2]=='4') ) { fl|=STBSP__INTMAX; f+=3; }308 else if ( ( f[1]=='3') && ( f[2]=='2') ) { f+=3; }309 else { fl|=((sizeof(void*)==8)?STBSP__INTMAX:0); ++f; } break;310 default: break;311 }312313 // handle each replacement314 switch( f[0] )315 {305 #define NUMSZ 512 // big enough for e308 (with commas) or e-307 306 char num[NUMSZ]; 316 #define STBSP__NUMSZ 512 // big enough for e308 (with commas) or e-307 317 char num[STBSP__NUMSZ]; 318 char lead[8]; 319 char tail[8]; 320 char *s;321 char const *h;311 rU32 l,n,cs;312 rU64 n64;313 #ifndef RR_SPRINTF_NOFLOAT 322 stbsp__uint32 l,n,cs;323 stbsp__uint64 n64;324 #ifndef STB_SPRINTF_NOFLOAT 325 double fv; 326 #endif316 rS32 dp; char const * sn;327 stbsp__int32 dp; char const * sn;328329 case 's':330 // get the string331 s = va_arg(va,char*); if (s==0) s = (char*)"null";332 // get the length333 sn = s;334 for(;;)335 { 325 if ((((rUINTa)sn)&3)==0) break;336 if ((((stbsp__uintptr)sn)&3)==0) break;337 lchk:338 if (sn[0]==0) goto ld;339 ++sn;340 }341 n = 0xffffffff;331 if (pr>=0) { n=(rU32)(sn-s); if (n>=(rU32)pr) goto ld; n=((rU32)(pr-n))>>2; }342 if (pr>=0) { n=(stbsp__uint32)(sn-s); if (n>=(stbsp__uint32)pr) goto ld; n=((stbsp__uint32)(pr-n))>>2; }343 while(n) 344 { 334 rU32 v=*(rU32*)sn;345 stbsp__uint32 v=*(stbsp__uint32*)sn;346 if ((v-0x01010101)&(~v)&0x80808080UL) goto lchk; 347 sn+=4; 348 --n;349 }350 goto lchk;351 ld:352342 l = (rU32) ( sn - s );353 l = (stbsp__uint32) ( sn - s );354 // clamp to precision344 if ( l > (rU32)pr ) l = pr;355 if ( l > (stbsp__uint32)pr ) l = pr;356 lead[0]=0; tail[0]=0; pr = 0; dp = 0; cs = 0;357 // copy the string in358 goto scopy;359360 case 'c': // char361 // get the character351 s = num + NUMSZ -1; *s = (char)va_arg(va,int);362 s = num + STBSP__NUMSZ -1; *s = (char)va_arg(va,int);363 l = 1;364 lead[0]=0; tail[0]=0; pr = 0; dp = 0; cs = 0;365 goto scopy;366
1 unmodified line
368 { int * d = va_arg(va,int*);369 *d = tlen + (int)( bf - buf ); }370 break;371361#ifdef RR_SPRINTF_NOFLOAT372#ifdef STB_SPRINTF_NOFLOAT373 case 'A': // float374 case 'a': // hex float375 case 'G': // float376 case 'g': // float
15 unmodified lines
392 hexfloat: 393 fv = va_arg(va,double);394 if (pr==-1) pr=6; // default is 6395 // read the double into a string385 if ( rrreal_to_parts( (rS64*)&n64, &dp, fv ) )386 fl |= NG;396 if ( stbsp__real_to_parts( (stbsp__int64*)&n64, &dp, fv ) )397 fl |= STBSP__NEGATIVE;398 399 s = num+64;400401 // sign391 lead[0]=0; if (fl&NG) { lead[0]=1; lead[1]='-'; } else if (fl&LS) { lead[0]=1; lead[1]=' '; } else if (fl&LP) { lead[0]=1; lead[1]='+'; };402 lead[0]=0; if (fl&STBSP__NEGATIVE) { lead[0]=1; lead[1]='-'; } else if (fl&STBSP__LEADINGSPACE) { lead[0]=1; lead[1]=' '; } else if (fl&STBSP__LEADINGPLUS) { lead[0]=1; lead[1]='+'; };403393 if (dp==-1023) dp=(n64)?-1022:0; else n64|=(((rU64)1)<<52);404 if (dp==-1023) dp=(n64)?-1022:0; else n64|=(((stbsp__uint64)1)<<52);405 n64<<=(64-56);395 if (pr<15) n64+=((((rU64)8)<<56)>>(pr*4));406 if (pr<15) n64+=((((stbsp__uint64)8)<<56)>>(pr*4));407 // add leading chars408 398 #ifdef RR_SPRINTF_MSVC_MODE409 #ifdef STB_SPRINTF_MSVC_MODE410 *s++='0';*s++='x';411 #else412 lead[1+lead[0]]='0'; lead[2+lead[0]]='x'; lead[0]+=2;413 #endif414 *s++=h[(n64>>60)&15]; n64<<=4;404 if ( pr ) *s++=RRperiod;415 if ( pr ) *s++=stbsp__period;416 sn = s;417418 // print the bits408 n = pr; if (n>13) n = 13; if (pr>(rS32)n) tz=pr-n; pr = 0;419 n = pr; if (n>13) n = 13; if (pr>(stbsp__int32)n) tz=pr-n; pr = 0;420 while(n--) { *s++=h[(n64>>60)&15]; n64<<=4; }421422 // print the expo423 tail[1]=h[17];
17 unmodified lines
441 dosmallfloat: 442 fv = va_arg(va,double);443 if (pr==-1) pr=6; else if (pr==0) pr = 1; // default is 6444 // read the double into a string434 if ( rrreal_to_str( &sn, &l, num, &dp, fv, (pr-1)|0x80000000 ) )435 fl |= NG;445 if ( stbsp__real_to_str( &sn, &l, num, &dp, fv, (pr-1)|0x80000000 ) )446 fl |= STBSP__NEGATIVE;447448 // clamp the precision and delete extra zeros after clamp449 n = pr;439 if ( l > (rU32)pr ) l = pr; while ((l>1)&&(pr)&&(sn[l-1]=='0')) { --pr; --l; }450 if ( l > (stbsp__uint32)pr ) l = pr; while ((l>1)&&(pr)&&(sn[l-1]=='0')) { --pr; --l; }451452 // should we use %e442 if ((dp<=-4)||(dp>(rS32)n))453 if ((dp<=-4)||(dp>(stbsp__int32)n))454 {444 if ( pr > (rS32)l ) pr = l-1; else if ( pr ) --pr; // when using %e, there is one digit before the decimal455 if ( pr > (stbsp__int32)l ) pr = l-1; else if ( pr ) --pr; // when using %e, there is one digit before the decimal456 goto doexpfromg;457 }458 // this is the insane action to get the pr to match %g sematics for %f448 if(dp>0) { pr=(dp<(rS32)l)?l-dp:0; } else { pr = -dp+((pr>(rS32)l)?l:pr); }459 if(dp>0) { pr=(dp<(stbsp__int32)l)?l-dp:0; } else { pr = -dp+((pr>(stbsp__int32)l)?l:pr); }460 goto dofloatfromg;461462 case 'E': // float463 h=hexu;
4 unmodified lines
468 doexp: 469 fv = va_arg(va,double);470 if (pr==-1) pr=6; // default is 6471 // read the double into a string461 if ( rrreal_to_str( &sn, &l, num, &dp, fv, pr|0x80000000 ) )462 fl |= NG;472 if ( stbsp__real_to_str( &sn, &l, num, &dp, fv, pr|0x80000000 ) )473 fl |= STBSP__NEGATIVE;474 doexpfromg: 475 tail[0]=0; 465 lead[0]=0; if (fl&NG) { lead[0]=1; lead[1]='-'; } else if (fl&LS) { lead[0]=1; lead[1]=' '; } else if (fl&LP) { lead[0]=1; lead[1]='+'; };466 if ( dp == RRSPECIAL ) { s=(char*)sn; cs=0; pr=0; goto scopy; }476 lead[0]=0; if (fl&STBSP__NEGATIVE) { lead[0]=1; lead[1]='-'; } else if (fl&STBSP__LEADINGSPACE) { lead[0]=1; lead[1]=' '; } else if (fl&STBSP__LEADINGPLUS) { lead[0]=1; lead[1]='+'; };477 if ( dp == STBSP__SPECIAL ) { s=(char*)sn; cs=0; pr=0; goto scopy; }478 s=num+64; 479 // handle leading chars480 *s++=sn[0];481471 if (pr) *s++=RRperiod;482 if (pr) *s++=stbsp__period;483484 // handle after decimal474 if ((l-1)>(rU32)pr) l=pr+1;485 if ((l-1)>(stbsp__uint32)pr) l=pr+1;486 for(n=1;n<l;n++) *s++=sn[n];487 // trailing zeros488 tz = pr-(l-1); pr=0;489 // dump expo490 tail[1]=h[0xe];491 dp -= 1;492 if (dp<0) { tail[2]='-'; dp=-dp;} else tail[2]='+';482 #ifdef RR_SPRINTF_MSVC_MODE493 #ifdef STB_SPRINTF_MSVC_MODE494 n = 5;495 #else496 n = (dp>=100)?5:4;497 #endif
5 unmodified lines
503 case 'f': // float504 fv = va_arg(va,double);505 doafloat: 506 // do kilos496 if (fl&KI) {while(fl<0x4000000) { if ((fv<1024.0) && (fv>-1024.0)) break; fv/=1024.0; fl+=0x1000000; }} 507 if (fl&STBSP__METRIC_SUFFIX) {while(fl<0x4000000) { if ((fv<1024.0) && (fv>-1024.0)) break; fv/=1024.0; fl+=0x1000000; }} 508 if (pr==-1) pr=6; // default is 6509 // read the double into a string499 if ( rrreal_to_str( &sn, &l, num, &dp, fv, pr ) )500 fl |= NG;510 if ( stbsp__real_to_str( &sn, &l, num, &dp, fv, pr ) )511 fl |= STBSP__NEGATIVE;512 dofloatfromg:513 tail[0]=0;514 // sign504 lead[0]=0; if (fl&NG) { lead[0]=1; lead[1]='-'; } else if (fl&LS) { lead[0]=1; lead[1]=' '; } else if (fl&LP) { lead[0]=1; lead[1]='+'; };505 if ( dp == RRSPECIAL ) { s=(char*)sn; cs=0; pr=0; goto scopy; }515 lead[0]=0; if (fl&STBSP__NEGATIVE) { lead[0]=1; lead[1]='-'; } else if (fl&STBSP__LEADINGSPACE) { lead[0]=1; lead[1]=' '; } else if (fl&STBSP__LEADINGPLUS) { lead[0]=1; lead[1]='+'; };516 if ( dp == STBSP__SPECIAL ) { s=(char*)sn; cs=0; pr=0; goto scopy; }517 s=num+64; 518519 // handle the three decimal varieties520 if (dp<=0) 521 { 511 rS32 i;522 stbsp__int32 i;523 // handle 0.000*000xxxx513 *s++='0'; if (pr) *s++=RRperiod; 514 n=-dp; if((rS32)n>pr) n=pr; i=n; while(i) { if ((((rUINTa)s)&3)==0) break; *s++='0'; --i; } while(i>=4) { *(rU32*)s=0x30303030; s+=4; i-=4; } while(i) { *s++='0'; --i; }515 if ((rS32)(l+n)>pr) l=pr-n; i=l; while(i) { *s++=*sn++; --i; }524 *s++='0'; if (pr) *s++=stbsp__period; 525 n=-dp; if((stbsp__int32)n>pr) n=pr; i=n; while(i) { if ((((stbsp__uintptr)s)&3)==0) break; *s++='0'; --i; } while(i>=4) { *(stbsp__uint32*)s=0x30303030; s+=4; i-=4; } while(i) { *s++='0'; --i; }526 if ((stbsp__int32)(l+n)>pr) l=pr-n; i=l; while(i) { *s++=*sn++; --i; }527 tz = pr-(n+l);528 cs = 1 + (3<<24); // how many tens did we write (for commas below)529 }530 else531 {521 cs = (fl&CS)?((600-(rU32)dp)%3):0;522 if ((rU32)dp>=l)532 cs = (fl&STBSP__TRIPLET_COMMA)?((600-(stbsp__uint32)dp)%3):0;533 if ((stbsp__uint32)dp>=l)534 {535 // handle xxxx000*000.0525 n=0; for(;;) { if ((fl&CS) && (++cs==4)) { cs = 0; *s++=RRcomma; } else { *s++=sn[n]; ++n; if (n>=l) break; } }526 if (n<(rU32)dp)536 n=0; for(;;) { if ((fl&STBSP__TRIPLET_COMMA) && (++cs==4)) { cs = 0; *s++=stbsp__comma; } else { *s++=sn[n]; ++n; if (n>=l) break; } }537 if (n<(stbsp__uint32)dp)538 {539 n = dp - n;529 if ((fl&CS)==0) { while(n) { if ((((rUINTa)s)&3)==0) break; *s++='0'; --n; } while(n>=4) { *(rU32*)s=0x30303030; s+=4; n-=4; } }530 while(n) { if ((fl&CS) && (++cs==4)) { cs = 0; *s++=RRcomma; } else { *s++='0'; --n; } }540 if ((fl&STBSP__TRIPLET_COMMA)==0) { while(n) { if ((((stbsp__uintptr)s)&3)==0) break; *s++='0'; --n; } while(n>=4) { *(stbsp__uint32*)s=0x30303030; s+=4; n-=4; } }541 while(n) { if ((fl&STBSP__TRIPLET_COMMA) && (++cs==4)) { cs = 0; *s++=stbsp__comma; } else { *s++='0'; --n; } }542 }543 cs = (int)(s-(num+64)) + (3<<24); // cs is how many tens533 if (pr) { *s++=RRperiod; tz=pr;}544 if (pr) { *s++=stbsp__period; tz=pr;}545 }546 else547 {548 // handle xxxxx.xxxx000*000538 n=0; for(;;) { if ((fl&CS) && (++cs==4)) { cs = 0; *s++=RRcomma; } else { *s++=sn[n]; ++n; if (n>=(rU32)dp) break; } }549 n=0; for(;;) { if ((fl&STBSP__TRIPLET_COMMA) && (++cs==4)) { cs = 0; *s++=stbsp__comma; } else { *s++=sn[n]; ++n; if (n>=(stbsp__uint32)dp) break; } }550 cs = (int)(s-(num+64)) + (3<<24); // cs is how many tens540 if (pr) *s++=RRperiod;541 if ((l-dp)>(rU32)pr) l=pr+dp;551 if (pr) *s++=stbsp__period;552 if ((l-dp)>(stbsp__uint32)pr) l=pr+dp;553 while(n<l) { *s++=sn[n]; ++n; }554 tz = pr-(l-dp);555 }556 }557 pr = 0;558 559 // handle k,m,g,t549 if (fl&KI) { tail[0]=1; tail[1]=' '; { if (fl>>24) { tail[2]="_kmgt"[fl>>24]; tail[0]=2; } } };560 if (fl&STBSP__METRIC_SUFFIX) { tail[0]=1; tail[1]=' '; { if (fl>>24) { tail[2]="_kmgt"[fl>>24]; tail[0]=2; } } };561562 flt_lead:563 // get the length that we copied553 l = (rU32) ( s-(num+64) );564 l = (stbsp__uint32) ( s-(num+64) );565 s=num+64; 566 goto scopy;567#endif568
4 unmodified lines
573 case 'b': // lower binary574 h = hex;575 binary:576 lead[0]=0;566 if (fl&LX) { lead[0]=2;lead[1]='0';lead[2]=h[0xb]; }577 if (fl&STBSP__LEADING_0X) { lead[0]=2;lead[1]='0';lead[2]=h[0xb]; }578 l=(8<<4)|(1<<8);579 goto radixnum;580581 case 'o': // octal582 h = hexu;583 lead[0]=0;573 if (fl&LX) { lead[0]=1;lead[1]='0'; }584 if (fl&STBSP__LEADING_0X) { lead[0]=1;lead[1]='0'; }585 l=(3<<4)|(3<<8);586 goto radixnum;587588 case 'p': // pointer578 fl |= (sizeof(void*)==8)?BI:0;589 fl |= (sizeof(void*)==8)?STBSP__INTMAX:0;590 pr = sizeof(void*)*2;580 fl &= ~LZ; // 'p' only prints the pointer with zeros591 fl &= ~STBSP__LEADINGZERO; // 'p' only prints the pointer with zeros592 // drop through to X593 594 case 'X': // upper binary595 h = hexu;
2 unmodified lines
598 case 'x': // lower binary599 h = hex; dohexb:600 l=(4<<4)|(4<<8);601 lead[0]=0;591 if (fl&LX) { lead[0]=2;lead[1]='0';lead[2]=h[16]; }602 if (fl&STBSP__LEADING_0X) { lead[0]=2;lead[1]='0';lead[2]=h[16]; }603 radixnum: 604 // get the number594 if ( fl&BI )595 n64 = va_arg(va,rU64);605 if ( fl&STBSP__INTMAX )606 n64 = va_arg(va,stbsp__uint64);607 else597 n64 = va_arg(va,rU32);608 n64 = va_arg(va,stbsp__uint32);609599 s = num + NUMSZ; dp = 0;610 s = num + STBSP__NUMSZ; dp = 0;611 // clear tail, and clear leading if value is zero612 tail[0]=0; if (n64==0) { lead[0]=0; if (pr==0) { l=0; cs = ( ((l>>4)&15)) << 24; goto scopy; } }613 // convert to string603 for(;;) { *--s = h[n64&((1<<(l>>8))-1)]; n64>>=(l>>8); if ( ! ( (n64) || ((rS32) ( (num+NUMSZ) - s ) < pr ) ) ) break; if ( fl&CS) { ++l; if ((l&15)==((l>>4)&15)) { l&=~15; *--s=RRcomma; } } };614 for(;;) { *--s = h[n64&((1<<(l>>8))-1)]; n64>>=(l>>8); if ( ! ( (n64) || ((stbsp__int32) ( (num+STBSP__NUMSZ) - s ) < pr ) ) ) break; if ( fl&STBSP__TRIPLET_COMMA) { ++l; if ((l&15)==((l>>4)&15)) { l&=~15; *--s=stbsp__comma; } } };615 // get the tens and the comma pos605 cs = (rU32) ( (num+NUMSZ) - s ) + ( ( ((l>>4)&15)) << 24 );616 cs = (stbsp__uint32) ( (num+STBSP__NUMSZ) - s ) + ( ( ((l>>4)&15)) << 24 );617 // get the length that we copied607 l = (rU32) ( (num+NUMSZ) - s );618 l = (stbsp__uint32) ( (num+STBSP__NUMSZ) - s );619 // copy it620 goto scopy;621622 case 'u': // unsigned623 case 'i':624 case 'd': // integer625 // get the integer and abs it615 if ( fl&BI )626 if ( fl&STBSP__INTMAX )627 {617 rS64 i64 = va_arg(va,rS64); n64 = (rU64)i64; if ((f[0]!='u') && (i64<0)) { n64=(rU64)-i64; fl|=NG; }628 stbsp__int64 i64 = va_arg(va,stbsp__int64); n64 = (stbsp__uint64)i64; if ((f[0]!='u') && (i64<0)) { n64=(stbsp__uint64)-i64; fl|=STBSP__NEGATIVE; }629 }630 else631 {621 rS32 i = va_arg(va,rS32); n64 = (rU32)i; if ((f[0]!='u') && (i<0)) { n64=(rU32)-i; fl|=NG; }632 stbsp__int32 i = va_arg(va,stbsp__int32); n64 = (stbsp__uint32)i; if ((f[0]!='u') && (i<0)) { n64=(stbsp__uint32)-i; fl|=STBSP__NEGATIVE; }633 }634624 #ifndef RR_SPRINTF_NOFLOAT625 if (fl&KI) { if (n64<1024) pr=0; else if (pr==-1) pr=1; fv=(double)(rS64)n64; goto doafloat; } 635 #ifndef STB_SPRINTF_NOFLOAT636 if (fl&STBSP__METRIC_SUFFIX) { if (n64<1024) pr=0; else if (pr==-1) pr=1; fv=(double)(stbsp__int64)n64; goto doafloat; } 637 #endif638639 // convert to string629 s = num+NUMSZ; l=0; 640 s = num+STBSP__NUMSZ; l=0; 641 642 for(;;)643 {644 // do in 32-bit chunks (avoid lots of 64-bit divides even with constant denominators)645 char * o=s-8;635 if (n64>=100000000) { n = (rU32)( n64 % 100000000); n64 /= 100000000; } else {n = (rU32)n64; n64 = 0; }636 if((fl&CS)==0) { while(n) { s-=2; *(rU16*)s=*(rU16*)&rrdiglookup[(n%100)*2]; n/=100; } }637 while (n) { if ( ( fl&CS) && (l++==3) ) { l=0; *--s=RRcomma; --o; } else { *--s=(char)(n%10)+'0'; n/=10; } }638 if (n64==0) { if ((s[0]=='0') && (s!=(num+NUMSZ))) ++s; break; }639 while (s!=o) if ( ( fl&CS) && (l++==3) ) { l=0; *--s=RRcomma; --o; } else { *--s='0'; }646 if (n64>=100000000) { n = (stbsp__uint32)( n64 % 100000000); n64 /= 100000000; } else {n = (stbsp__uint32)n64; n64 = 0; }647 if((fl&STBSP__TRIPLET_COMMA)==0) { while(n) { s-=2; *(stbsp__uint16*)s=*(stbsp__uint16*)&stbsp__digitpair[(n%100)*2]; n/=100; } }648 while (n) { if ( ( fl&STBSP__TRIPLET_COMMA) && (l++==3) ) { l=0; *--s=stbsp__comma; --o; } else { *--s=(char)(n%10)+'0'; n/=10; } }649 if (n64==0) { if ((s[0]=='0') && (s!=(num+STBSP__NUMSZ))) ++s; break; }650 while (s!=o) if ( ( fl&STBSP__TRIPLET_COMMA) && (l++==3) ) { l=0; *--s=stbsp__comma; --o; } else { *--s='0'; }651 }652653 tail[0]=0;654 // sign644 lead[0]=0; if (fl&NG) { lead[0]=1; lead[1]='-'; } else if (fl&LS) { lead[0]=1; lead[1]=' '; } else if (fl&LP) { lead[0]=1; lead[1]='+'; };655 lead[0]=0; if (fl&STBSP__NEGATIVE) { lead[0]=1; lead[1]='-'; } else if (fl&STBSP__LEADINGSPACE) { lead[0]=1; lead[1]=' '; } else if (fl&STBSP__LEADINGPLUS) { lead[0]=1; lead[1]='+'; };656657 // get the length that we copied647 l = (rU32) ( (num+NUMSZ) - s ); if ( l == 0 ) { *--s='0'; l = 1; }658 l = (stbsp__uint32) ( (num+STBSP__NUMSZ) - s ); if ( l == 0 ) { *--s='0'; l = 1; }659 cs = l + (3<<24);660 if (pr<0) pr = 0;661662 scopy: 663 // get fw=leading/trailing space, pr=leading zeros653 if (pr<(rS32)l) pr = l;664 if (pr<(stbsp__int32)l) pr = l;665 n = pr + lead[0] + tail[0] + tz;655 if (fw<(rS32)n) fw = n;666 if (fw<(stbsp__int32)n) fw = n;667 fw -= n;668 pr -= l;669670 // handle right justify and leading zeros660 if ( (fl&LJ)==0 )671 if ( (fl&STBSP__LEFTJUST)==0 )672 {662 if (fl&LZ) // if leading zeros, everything is in pr673 if (fl&STBSP__LEADINGZERO) // if leading zeros, everything is in pr674 { 675 pr = (fw>pr)?fw:pr;676 fw = 0;677 }678 else679 {669 fl &= ~CS; // if no leading zeros, then no commas680 fl &= ~STBSP__TRIPLET_COMMA; // if no leading zeros, then no commas681 }682 }683684 // copy the spaces and/or zeros685 if (fw+pr)686 {676 rS32 i; rU32 c; 687 stbsp__int32 i; stbsp__uint32 c; 688689 // copy leading spaces (or when doing %8.4d stuff)679 if ( (fl&LJ)==0 ) while(fw>0) { cb_buf_clamp(i,fw); fw -= i; while(i) { if ((((rUINTa)bf)&3)==0) break; *bf++=' '; --i; } while(i>=4) { *(rU32*)bf=0x20202020; bf+=4; i-=4; } while (i) {*bf++=' '; --i;} chk_cb_buf(1); }690 if ( (fl&STBSP__LEFTJUST)==0 ) while(fw>0) { stbsp__cb_buf_clamp(i,fw); fw -= i; while(i) { if ((((stbsp__uintptr)bf)&3)==0) break; *bf++=' '; --i; } while(i>=4) { *(stbsp__uint32*)bf=0x20202020; bf+=4; i-=4; } while (i) {*bf++=' '; --i;} stbsp__chk_cb_buf(1); }691 692 // copy leader682 sn=lead+1; while(lead[0]) { cb_buf_clamp(i,lead[0]); lead[0] -= (char)i; while (i) {*bf++=*sn++; --i;} chk_cb_buf(1); }693 sn=lead+1; while(lead[0]) { stbsp__cb_buf_clamp(i,lead[0]); lead[0] -= (char)i; while (i) {*bf++=*sn++; --i;} stbsp__chk_cb_buf(1); }694 695 // copy leading zeros696 c = cs >> 24; cs &= 0xffffff;686 cs = (fl&CS)?((rU32)(c-((pr+cs)%(c+1)))):0;687 while(pr>0) { cb_buf_clamp(i,pr); pr -= i; if((fl&CS)==0) { while(i) { if ((((rUINTa)bf)&3)==0) break; *bf++='0'; --i; } while(i>=4) { *(rU32*)bf=0x30303030; bf+=4; i-=4; } } while (i) { if((fl&CS) && (cs++==c)) { cs = 0; *bf++=RRcomma; } else *bf++='0'; --i; } chk_cb_buf(1); }697 cs = (fl&STBSP__TRIPLET_COMMA)?((stbsp__uint32)(c-((pr+cs)%(c+1)))):0;698 while(pr>0) { stbsp__cb_buf_clamp(i,pr); pr -= i; if((fl&STBSP__TRIPLET_COMMA)==0) { while(i) { if ((((stbsp__uintptr)bf)&3)==0) break; *bf++='0'; --i; } while(i>=4) { *(stbsp__uint32*)bf=0x30303030; bf+=4; i-=4; } } while (i) { if((fl&STBSP__TRIPLET_COMMA) && (cs++==c)) { cs = 0; *bf++=stbsp__comma; } else *bf++='0'; --i; } stbsp__chk_cb_buf(1); }699 }700701 // copy leader if there is still one691 sn=lead+1; while(lead[0]) { rS32 i; cb_buf_clamp(i,lead[0]); lead[0] -= (char)i; while (i) {*bf++=*sn++; --i;} chk_cb_buf(1); }702 sn=lead+1; while(lead[0]) { stbsp__int32 i; stbsp__cb_buf_clamp(i,lead[0]); lead[0] -= (char)i; while (i) {*bf++=*sn++; --i;} stbsp__chk_cb_buf(1); }703704 // copy the string694 n = l; while (n) { rS32 i; cb_buf_clamp(i,n); n-=i; RR_UNALIGNED( while(i>=4) { *(rU32*)bf=*(rU32*)s; bf+=4; s+=4; i-=4; } ) while (i) {*bf++=*s++; --i;} chk_cb_buf(1); }705 n = l; while (n) { stbsp__int32 i; stbsp__cb_buf_clamp(i,n); n-=i; STBSP__UNALIGNED( while(i>=4) { *(stbsp__uint32*)bf=*(stbsp__uint32*)s; bf+=4; s+=4; i-=4; } ) while (i) {*bf++=*s++; --i;} stbsp__chk_cb_buf(1); }706707 // copy trailing zeros697 while(tz) { rS32 i; cb_buf_clamp(i,tz); tz -= i; while(i) { if ((((rUINTa)bf)&3)==0) break; *bf++='0'; --i; } while(i>=4) { *(rU32*)bf=0x30303030; bf+=4; i-=4; } while (i) {*bf++='0'; --i;} chk_cb_buf(1); }708 while(tz) { stbsp__int32 i; stbsp__cb_buf_clamp(i,tz); tz -= i; while(i) { if ((((stbsp__uintptr)bf)&3)==0) break; *bf++='0'; --i; } while(i>=4) { *(stbsp__uint32*)bf=0x30303030; bf+=4; i-=4; } while (i) {*bf++='0'; --i;} stbsp__chk_cb_buf(1); }709710 // copy tail if there is one700 sn=tail+1; while(tail[0]) { rS32 i; cb_buf_clamp(i,tail[0]); tail[0] -= (char)i; while (i) {*bf++=*sn++; --i;} chk_cb_buf(1); }711 sn=tail+1; while(tail[0]) { stbsp__int32 i; stbsp__cb_buf_clamp(i,tail[0]); tail[0] -= (char)i; while (i) {*bf++=*sn++; --i;} stbsp__chk_cb_buf(1); }712713 // handle the left justify703 if (fl&LJ) if (fw>0) { while (fw) { rS32 i; cb_buf_clamp(i,fw); fw-=i; while(i) { if ((((rUINTa)bf)&3)==0) break; *bf++=' '; --i; } while(i>=4) { *(rU32*)bf=0x20202020; bf+=4; i-=4; } while (i--) *bf++=' '; chk_cb_buf(1); } }714 if (fl&STBSP__LEFTJUST) if (fw>0) { while (fw) { stbsp__int32 i; stbsp__cb_buf_clamp(i,fw); fw-=i; while(i) { if ((((stbsp__uintptr)bf)&3)==0) break; *bf++=' '; --i; } while(i>=4) { *(stbsp__uint32*)bf=0x20202020; bf+=4; i-=4; } while (i--) *bf++=' '; stbsp__chk_cb_buf(1); } }715 break;716717 default: // unknown, just copy code707 s = num + NUMSZ -1; *s = f[0];718 s = num + STBSP__NUMSZ -1; *s = f[0];719 l = 1;720 fw=pr=fl=0;721 lead[0]=0; tail[0]=0; pr = 0; dp = 0; cs = 0;722 goto scopy;
4 unmodified lines
727728 if (!callback) 729 *bf = 0;730 else720 flush_cb();731 stbsp__flush_cb();732 733 done:734 return tlen + (int)(bf-buf);735}736737// cleanup727#undef LJ728#undef LP729#undef LS730#undef LX731#undef LZ732#undef BI733#undef CS734#undef NG735#undef KI736#undef NUMSZ737#undef chk_cb_bufL738#undef chk_cb_buf739#undef flush_cb740#undef cb_buf_clamp738#undef STBSP__LEFTJUST739#undef STBSP__LEADINGPLUS740#undef STBSP__LEADINGSPACE741#undef STBSP__LEADING_0X742#undef STBSP__LEADINGZERO743#undef STBSP__INTMAX744#undef STBSP__TRIPLET_COMMA745#undef STBSP__NEGATIVE746#undef STBSP__METRIC_SUFFIX747#undef STBSP__NUMSZ748#undef stbsp__chk_cb_bufL749#undef stbsp__chk_cb_buf750#undef stbsp__flush_cb751#undef stbsp__cb_buf_clamp752753// ============================================================================754// wrapper functions755745RRPUBLIC_DEF int RR_SPRINTF_DECORATE( sprintf )( char * buf, char const * fmt, ... )756STBSP__PUBLICDEF int STB_SPRINTF_DECORATE( sprintf )( char * buf, char const * fmt, ... )757{758 va_list va;759 va_start( va, fmt );749 return RR_SPRINTF_DECORATE( vsprintfcb )( 0, 0, buf, fmt, va );760 return STB_SPRINTF_DECORATE( vsprintfcb )( 0, 0, buf, fmt, va );761}762752typedef struct RRCCS763typedef struct stbsp__context764{765 char * buf;766 int count;756 char tmp[ RR_SPRINTF_MIN ];757} RRCCS;767 char tmp[ STB_SPRINTF_MIN ];768} stbsp__context;769759static char * rrclampcallback( char * buf, void * user, int len )770static char * stbsp__clamp_callback( char * buf, void * user, int len )771{761 RRCCS * c = (RRCCS*)user;772 stbsp__context * c = (stbsp__context*)user;773774 if ( len > c->count ) len = c->count;775776 if (len)
8 unmodified lines
785 c->count -= len;786 }787 788 if ( c->count <= 0 ) return 0;778 return ( c->count >= RR_SPRINTF_MIN ) ? c->buf : c->tmp; // go direct into buffer if you can789 return ( c->count >= STB_SPRINTF_MIN ) ? c->buf : c->tmp; // go direct into buffer if you can790}791781RRPUBLIC_DEF int RR_SPRINTF_DECORATE( vsnprintf )( char * buf, int count, char const * fmt, va_list va )792STBSP__PUBLICDEF int STB_SPRINTF_DECORATE( vsnprintf )( char * buf, int count, char const * fmt, va_list va )793{783 RRCCS c;794 stbsp__context c;795 int l;796797 if ( count == 0 )798 return 0;799800 c.buf = buf;801 c.count = count;802792 RR_SPRINTF_DECORATE( vsprintfcb )( rrclampcallback, &c, rrclampcallback(0,&c,0), fmt, va );803 STB_SPRINTF_DECORATE( vsprintfcb )( stbsp__clamp_callback, &c, stbsp__clamp_callback(0,&c,0), fmt, va );804 805 // zero-terminate806 l = (int)( c.buf - buf );807 if ( l >= count ) // should never be greater, only equal (or less) than count
2 unmodified lines
810811 return l;812}813803RRPUBLIC_DEF int RR_SPRINTF_DECORATE( snprintf )( char * buf, int count, char const * fmt, ... )814STBSP__PUBLICDEF int STB_SPRINTF_DECORATE( snprintf )( char * buf, int count, char const * fmt, ... )815{816 va_list va;817 va_start( va, fmt );818808 return RR_SPRINTF_DECORATE( vsnprintf )( buf, count, fmt, va );819 return STB_SPRINTF_DECORATE( vsnprintf )( buf, count, fmt, va );820}821811RRPUBLIC_DEF int RR_SPRINTF_DECORATE( vsprintf )( char * buf, char const * fmt, va_list va )822STBSP__PUBLICDEF int STB_SPRINTF_DECORATE( vsprintf )( char * buf, char const * fmt, va_list va )823{813 return RR_SPRINTF_DECORATE( vsprintfcb )( 0, 0, buf, fmt, va );824 return STB_SPRINTF_DECORATE( vsprintfcb )( 0, 0, buf, fmt, va );825}826827// =======================================================================828// low level float utility functions829819#ifndef RR_SPRINTF_NOFLOAT830#ifndef STB_SPRINTF_NOFLOAT831821 // copies d to bits w/ strict aliasing (this compiles to nothing on /Ox)822 #define RRCOPYFP(dest,src) { int cn; for(cn=0;cn<8;cn++) ((char*)&dest)[cn]=((char*)&src)[cn]; }832// copies d to bits w/ strict aliasing (this compiles to nothing on /Ox)833#define STBSP__COPYFP(dest,src) { int cn; for(cn=0;cn<8;cn++) ((char*)&dest)[cn]=((char*)&src)[cn]; }834 835// get float info825static rS32 rrreal_to_parts( rS64 * bits, rS32 * expo, double value )836static stbsp__int32 stbsp__real_to_parts( stbsp__int64 * bits, stbsp__int32 * expo, double value )837{838 double d;828 rS64 b = 0;839 stbsp__int64 b = 0;840841 // load value and round at the frac_digits842 d = value;843833 RRCOPYFP( b, d );844 STBSP__COPYFP( b, d );845835 *bits = b & ((((rU64)1)<<52)-1);836 *expo = ((b >> 52) & 2047)-1023;846 *bits = b & ((((stbsp__uint64)1)<<52)-1);847 *expo = (stbsp__int32) (((b >> 52) & 2047)-1023);848 838 return (rS32)(b >> 63);849 return (stbsp__int32)(b >> 63);850}851841static double const rrbot[23]={1e+000,1e+001,1e+002,1e+003,1e+004,1e+005,1e+006,1e+007,1e+008,1e+009,1e+010,1e+011,1e+012,1e+013,1e+014,1e+015,1e+016,1e+017,1e+018,1e+019,1e+020,1e+021,1e+022};842static double const rrnegbot[22]={1e-001,1e-002,1e-003,1e-004,1e-005,1e-006,1e-007,1e-008,1e-009,1e-010,1e-011,1e-012,1e-013,1e-014,1e-015,1e-016,1e-017,1e-018,1e-019,1e-020,1e-021,1e-022};843static double const rrnegboterr[22]={-5.551115123125783e-018,-2.0816681711721684e-019,-2.0816681711721686e-020,-4.7921736023859299e-021,-8.1803053914031305e-022,4.5251888174113741e-023,4.5251888174113739e-024,-2.0922560830128471e-025,-6.2281591457779853e-026,-3.6432197315497743e-027,6.0503030718060191e-028,2.0113352370744385e-029,-3.0373745563400371e-030,1.1806906454401013e-032,-7.7705399876661076e-032,2.0902213275965398e-033,-7.1542424054621921e-034,-7.1542424054621926e-035,2.4754073164739869e-036,5.4846728545790429e-037,9.2462547772103625e-038,-4.8596774326570872e-039};844static double const rrtop[13]={1e+023,1e+046,1e+069,1e+092,1e+115,1e+138,1e+161,1e+184,1e+207,1e+230,1e+253,1e+276,1e+299};845static double const rrnegtop[13]={1e-023,1e-046,1e-069,1e-092,1e-115,1e-138,1e-161,1e-184,1e-207,1e-230,1e-253,1e-276,1e-299};846static double const rrtoperr[13]={8388608,6.8601809640529717e+028,-7.253143638152921e+052,-4.3377296974619174e+075,-1.5559416129466825e+098,-3.2841562489204913e+121,-3.7745893248228135e+144,-1.7356668416969134e+167,-3.8893577551088374e+190,-9.9566444326005119e+213,6.3641293062232429e+236,-5.2069140800249813e+259,-5.2504760255204387e+282};847static double const rrnegtoperr[13]={3.9565301985100693e-040,-2.299904345391321e-063,3.6506201437945798e-086,1.1875228833981544e-109,-5.0644902316928607e-132,-6.7156837247865426e-155,-2.812077463003139e-178,-5.7778912386589953e-201,7.4997100559334532e-224,-4.6439668915134491e-247,-6.3691100762962136e-270,-9.436808465446358e-293,8.0970921678014997e-317};852static double const stbsp__bot[23]={1e+000,1e+001,1e+002,1e+003,1e+004,1e+005,1e+006,1e+007,1e+008,1e+009,1e+010,1e+011,1e+012,1e+013,1e+014,1e+015,1e+016,1e+017,1e+018,1e+019,1e+020,1e+021,1e+022};853static double const stbsp__negbot[22]={1e-001,1e-002,1e-003,1e-004,1e-005,1e-006,1e-007,1e-008,1e-009,1e-010,1e-011,1e-012,1e-013,1e-014,1e-015,1e-016,1e-017,1e-018,1e-019,1e-020,1e-021,1e-022};854static double const stbsp__negboterr[22]={-5.551115123125783e-018,-2.0816681711721684e-019,-2.0816681711721686e-020,-4.7921736023859299e-021,-8.1803053914031305e-022,4.5251888174113741e-023,4.5251888174113739e-024,-2.0922560830128471e-025,-6.2281591457779853e-026,-3.6432197315497743e-027,6.0503030718060191e-028,2.0113352370744385e-029,-3.0373745563400371e-030,1.1806906454401013e-032,-7.7705399876661076e-032,2.0902213275965398e-033,-7.1542424054621921e-034,-7.1542424054621926e-035,2.4754073164739869e-036,5.4846728545790429e-037,9.2462547772103625e-038,-4.8596774326570872e-039};855static double const stbsp__top[13]={1e+023,1e+046,1e+069,1e+092,1e+115,1e+138,1e+161,1e+184,1e+207,1e+230,1e+253,1e+276,1e+299};856static double const stbsp__negtop[13]={1e-023,1e-046,1e-069,1e-092,1e-115,1e-138,1e-161,1e-184,1e-207,1e-230,1e-253,1e-276,1e-299};857static double const stbsp__toperr[13]={8388608,6.8601809640529717e+028,-7.253143638152921e+052,-4.3377296974619174e+075,-1.5559416129466825e+098,-3.2841562489204913e+121,-3.7745893248228135e+144,-1.7356668416969134e+167,-3.8893577551088374e+190,-9.9566444326005119e+213,6.3641293062232429e+236,-5.2069140800249813e+259,-5.2504760255204387e+282};858static double const stbsp__negtoperr[13]={3.9565301985100693e-040,-2.299904345391321e-063,3.6506201437945798e-086,1.1875228833981544e-109,-5.0644902316928607e-132,-6.7156837247865426e-155,-2.812077463003139e-178,-5.7778912386589953e-201,7.4997100559334532e-224,-4.6439668915134491e-247,-6.3691100762962136e-270,-9.436808465446358e-293,8.0970921678014997e-317};859860#if defined(_MSC_VER) && (_MSC_VER<=1200) 850static rU64 const rrpot[20]={1,10,100,1000, 10000,100000,1000000,10000000, 100000000,1000000000,10000000000,100000000000, 1000000000000,10000000000000,100000000000000,1000000000000000, 10000000000000000,100000000000000000,1000000000000000000,10000000000000000000U };851#define rrtento19th ((rU64)1000000000000000000)861static stbsp__uint64 const stbsp__powten[20]={1,10,100,1000, 10000,100000,1000000,10000000, 100000000,1000000000,10000000000,100000000000, 1000000000000,10000000000000,100000000000000,1000000000000000, 10000000000000000,100000000000000000,1000000000000000000,10000000000000000000U };862#define stbsp__tento19th ((stbsp__uint64)1000000000000000000)863#else853static rU64 const rrpot[20]={1,10,100,1000, 10000,100000,1000000,10000000, 100000000,1000000000,10000000000ULL,100000000000ULL, 1000000000000ULL,10000000000000ULL,100000000000000ULL,1000000000000000ULL, 10000000000000000ULL,100000000000000000ULL,1000000000000000000ULL,10000000000000000000ULL };854#define rrtento19th (1000000000000000000ULL)864static stbsp__uint64 const stbsp__powten[20]={1,10,100,1000, 10000,100000,1000000,10000000, 100000000,1000000000,10000000000ULL,100000000000ULL, 1000000000000ULL,10000000000000ULL,100000000000000ULL,1000000000000000ULL, 10000000000000000ULL,100000000000000000ULL,1000000000000000000ULL,10000000000000000000ULL };865#define stbsp__tento19th (1000000000000000000ULL)866#endif867857#define rrddmulthi(oh,ol,xh,yh) \868#define stbsp__ddmulthi(oh,ol,xh,yh) \869{ \870 double ahi=0,alo,bhi=0,blo; \860 rS64 bt; \871 stbsp__int64 bt; \872 oh = xh * yh; \862 RRCOPYFP(bt,xh); bt&=((~(rU64)0)<<27); RRCOPYFP(ahi,bt); alo = xh-ahi; \863 RRCOPYFP(bt,yh); bt&=((~(rU64)0)<<27); RRCOPYFP(bhi,bt); blo = yh-bhi; \873 STBSP__COPYFP(bt,xh); bt&=((~(stbsp__uint64)0)<<27); STBSP__COPYFP(ahi,bt); alo = xh-ahi; \874 STBSP__COPYFP(bt,yh); bt&=((~(stbsp__uint64)0)<<27); STBSP__COPYFP(bhi,bt); blo = yh-bhi; \875 ol = ((ahi*bhi-oh)+ahi*blo+alo*bhi)+alo*blo; \876}877867#define rrddtoS64(ob,xh,xl) \878#define stbsp__ddtoS64(ob,xh,xl) \879{ \880 double ahi=0,alo,vh,t;\870 ob = (rS64)ph;\881 ob = (stbsp__int64)ph;\882 vh=(double)ob;\883 ahi = ( xh - vh );\884 t = ( ahi - xh );\885 alo = (xh-(ahi-t))-(vh+t);\875 ob += (rS64)(ahi+alo+xl);\886 ob += (stbsp__int64)(ahi+alo+xl);\887}888889879#define rrddrenorm(oh,ol) { double s; s=oh+ol; ol=ol-(s-oh); oh=s; }890#define stbsp__ddrenorm(oh,ol) { double s; s=oh+ol; ol=ol-(s-oh); oh=s; }891881#define rrddmultlo(oh,ol,xh,xl,yh,yl) \892#define stbsp__ddmultlo(oh,ol,xh,xl,yh,yl) \893 ol = ol + ( xh*yl + xl*yh ); \894884#define rrddmultlos(oh,ol,xh,yl) \895#define stbsp__ddmultlos(oh,ol,xh,yl) \896 ol = ol + ( xh*yl ); \897887static void rrraise_to_power10( double *ohi, double *olo, double d, rS32 power ) // power can be -323 to +350898static void stbsp__raise_to_power10( double *ohi, double *olo, double d, stbsp__int32 power ) // power can be -323 to +350899{900 double ph, pl;901 if ((power>=0) && (power<=22))902 {892 rrddmulthi(ph,pl,d,rrbot[power]);903 stbsp__ddmulthi(ph,pl,d,stbsp__bot[power]);904 }905 else906 {896 rS32 e,et,eb;907 stbsp__int32 e,et,eb;908 double p2h,p2l;909910 e=power; if (power<0) e=-e; 911 et = (e*0x2c9)>>14;/* %23 */ if (et>13) et=13; eb = e-(et*23);912913 ph = d; pl = 0.0;914 if (power<0)915 {905 if (eb) { --eb; rrddmulthi(ph,pl,d,rrnegbot[eb]); rrddmultlos(ph,pl,d,rrnegboterr[eb]); }916 if (eb) { --eb; stbsp__ddmulthi(ph,pl,d,stbsp__negbot[eb]); stbsp__ddmultlos(ph,pl,d,stbsp__negboterr[eb]); }917 if (et)918 { 908 rrddrenorm(ph,pl);909 --et; rrddmulthi(p2h,p2l,ph,rrnegtop[et]); rrddmultlo(p2h,p2l,ph,pl,rrnegtop[et],rrnegtoperr[et]); ph=p2h;pl=p2l;919 stbsp__ddrenorm(ph,pl);920 --et; stbsp__ddmulthi(p2h,p2l,ph,stbsp__negtop[et]); stbsp__ddmultlo(p2h,p2l,ph,pl,stbsp__negtop[et],stbsp__negtoperr[et]); ph=p2h;pl=p2l;921 }922 }923 else924 {925 if (eb) 926 { 927 e = eb; if (eb>22) eb=22; e -= eb;917 rrddmulthi(ph,pl,d,rrbot[eb]); 918 if ( e ) { rrddrenorm(ph,pl); rrddmulthi(p2h,p2l,ph,rrbot[e]); rrddmultlos(p2h,p2l,rrbot[e],pl); ph=p2h;pl=p2l; }928 stbsp__ddmulthi(ph,pl,d,stbsp__bot[eb]); 929 if ( e ) { stbsp__ddrenorm(ph,pl); stbsp__ddmulthi(p2h,p2l,ph,stbsp__bot[e]); stbsp__ddmultlos(p2h,p2l,stbsp__bot[e],pl); ph=p2h;pl=p2l; }930 }931 if (et)932 {922 rrddrenorm(ph,pl);923 --et; rrddmulthi(p2h,p2l,ph,rrtop[et]); rrddmultlo(p2h,p2l,ph,pl,rrtop[et],rrtoperr[et]); ph=p2h;pl=p2l;933 stbsp__ddrenorm(ph,pl);934 --et; stbsp__ddmulthi(p2h,p2l,ph,stbsp__top[et]); stbsp__ddmultlo(p2h,p2l,ph,pl,stbsp__top[et],stbsp__toperr[et]); ph=p2h;pl=p2l;935 }936 }937 }927 rrddrenorm(ph,pl);938 stbsp__ddrenorm(ph,pl);939 *ohi = ph; *olo = pl;940}941942// given a float value, returns the significant bits in bits, and the position of the943// decimal point in decimal_pos. +/-INF and NAN are specified by special values944// returned in the decimal_pos parameter.945// frac_digits is absolute normally, but if you want from first significant digits (got %g and %e), or in 0x80000000935static rS32 rrreal_to_str( char const * * start, rU32 * len, char *out, rS32 * decimal_pos, double value, rU32 frac_digits )946static stbsp__int32 stbsp__real_to_str( char const * * start, stbsp__uint32 * len, char *out, stbsp__int32 * decimal_pos, double value, stbsp__uint32 frac_digits )947{948 double d;938 rS64 bits = 0;939 rS32 expo, e, ng, tens;949 stbsp__int64 bits = 0;950 stbsp__int32 expo, e, ng, tens;951952 d = value;942 RRCOPYFP(bits,d);943 expo = (bits >> 52) & 2047;944 ng = (rS32)(bits >> 63);953 STBSP__COPYFP(bits,d);954 expo = (stbsp__int32) ((bits >> 52) & 2047);955 ng = (stbsp__int32)(bits >> 63);956 if (ng) d=-d;957958 if ( expo == 2047 ) // is nan or inf?959 {949 *start = (bits&((((rU64)1)<<52)-1)) ? "NaN" : "Inf";950 *decimal_pos = RRSPECIAL;960 *start = (bits&((((stbsp__uint64)1)<<52)-1)) ? "NaN" : "Inf";961 *decimal_pos = STBSP__SPECIAL;962 *len = 3;963 return ng;964 } 965
7 unmodified lines
973 return ng;974 }975 // find the right expo for denormals976 {966 rS64 v = ((rU64)1)<<51;977 stbsp__int64 v = ((stbsp__uint64)1)<<51;978 while ((bits&v)==0) { --expo; v >>= 1; }979 }980 }981
4 unmodified lines
986 // log10 estimate - very specifically tweaked to hit or undershoot by no more than 1 of log10 of all expos 1..2046987 tens=expo-1023; tens = (tens<0)?((tens*617)/2048):(((tens*1233)/4096)+1);988989 // move the significant bits into position and stick them into an int 979 rrraise_to_power10( &ph, &pl, d, 18-tens );990 stbsp__raise_to_power10( &ph, &pl, d, 18-tens );991992 // get full as much precision from double-double as possible982 rrddtoS64( bits, ph,pl );993 stbsp__ddtoS64( bits, ph,pl );994995 // check if we undershot985 if ( ((rU64)bits) >= rrtento19th ) ++tens; 996 if ( ((stbsp__uint64)bits) >= stbsp__tento19th ) ++tens; 997 }998999 // now do the rounding in integer land1000 frac_digits = ( frac_digits & 0x80000000 ) ? ( (frac_digits&0x7ffffff) + 1 ) : ( tens + frac_digits );1001 if ( ( frac_digits < 24 ) )1002 {992 rU32 dg = 1; if ((rU64)bits >= rrpot[9] ) dg=10; while( (rU64)bits >= rrpot[dg] ) { ++dg; if (dg==20) goto noround; }1003 stbsp__uint32 dg = 1; if ((stbsp__uint64)bits >= stbsp__powten[9] ) dg=10; while( (stbsp__uint64)bits >= stbsp__powten[dg] ) { ++dg; if (dg==20) goto noround; }1004 if ( frac_digits < dg )1005 {995 rU64 r;1006 stbsp__uint64 r;1007 // add 0.5 at the right position and round1008 e = dg - frac_digits;998 if ( (rU32)e >= 24 ) goto noround;999 r = rrpot[e];1009 if ( (stbsp__uint32)e >= 24 ) goto noround;1010 r = stbsp__powten[e];1011 bits = bits + (r/2);1001 if ( (rU64)bits >= rrpot[dg] ) ++tens;1012 if ( (stbsp__uint64)bits >= stbsp__powten[dg] ) ++tens;1013 bits /= r;1014 } 1015 noround:;1016 }10171018 // kill long trailing runs of zeros1019 if ( bits )1020 {1010 rU32 n; for(;;) { if ( bits<=0xffffffff ) break; if (bits%1000) goto donez; bits/=1000; } n = (rU32)bits; while ((n%1000)==0) n/=1000; bits=n; donez:;1021 stbsp__uint32 n;1022 for(;;) { if ( bits<=0xffffffff ) break; if (bits%1000) goto donez; bits/=1000; }1023 n = (stbsp__uint32)bits;1024 while ((n%1000)==0) n/=1000;1025 bits=n;1026 donez:;1027 }10281029 // convert to string1030 out += 64;1031 e = 0; 1032 for(;;)1033 {1018 rU32 n;1034 stbsp__uint32 n;1035 char * o = out-8;1036 // do the conversion in chunks of U32s (avoid most 64-bit divides, worth it, constant denomiators be damned)1021 if (bits>=100000000) { n = (rU32)( bits % 100000000); bits /= 100000000; } else {n = (rU32)bits; bits = 0; }1022 while(n) { out-=2; *(rU16*)out=*(rU16*)&rrdiglookup[(n%100)*2]; n/=100; e+=2; }1037 if (bits>=100000000) { n = (stbsp__uint32)( bits % 100000000); bits /= 100000000; } else {n = (stbsp__uint32)bits; bits = 0; }1038 while(n) { out-=2; *(stbsp__uint16*)out=*(stbsp__uint16*)&stbsp__digitpair[(n%100)*2]; n/=100; e+=2; }1039 if (bits==0) { if ((e) && (out[0]=='0')) { ++out; --e; } break; }1040 while( out!=o ) { *--out ='0'; ++e; }1041 }1042
2 unmodified lines
1045 *len = e;1046 return ng;1047}10481033#undef rrddmulthi1034#undef rrddrenorm1035#undef rrddmultlo1036#undef rrddmultlos1037#undef RRSPECIAL 1038#undef RRCOPYFP1049#undef stbsp__ddmulthi1050#undef stbsp__ddrenorm1051#undef stbsp__ddmultlo1052#undef stbsp__ddmultlos1053#undef STBSP__SPECIAL 1054#undef STBSP__COPYFP1055 1040#endif1056#endif // STB_SPRINTF_NOFLOAT10571058// clean up1043#undef rU161044#undef rU32 1045#undef rS32 1046#undef rU641047#undef rS641048#undef RRPUBLIC_DEC1049#undef RRPUBLIC_DEF1050#undef RR_SPRINTF_DECORATE1051#undef RR_UNALIGNED1059#undef stbsp__uint161060#undef stbsp__uint32 1061#undef stbsp__int32 1062#undef stbsp__uint641063#undef stbsp__int641064#undef STBSP__UNALIGNED10651053#endif10541055#endif1066#endif // STB_SPRINTF_IMPLEMENTATION
modified:stb.h+1 added
728 unmodified lines
729STB_EXTERN int stb_snprintf(char *s, size_t n, const char *fmt, ...);730STB_EXTERN int stb_vsnprintf(char *s, size_t n, const char *fmt, va_list v);731732#ifdef STB_DEFINE733734int stb_vsnprintf(char *s, size_t n, const char *fmt, va_list v)735{736 int res;737 #ifdef _WIN32
13540 unmodified lines