You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Firstly, I like to appreciate the author for this lib. Understand it is the most downloaded lib for this function and has been stable for years.
Maybe I missed out something obvious, can someone in the community tell me what happens here:
// tested on nodejs v14, v18constsprintf=require('sprintf-js');letnum=150460469257;// 0x2308249009// simpliy convert number to hex stringconsthexStr_native=num.toString(16);consthexStr_sprintfjs=sprintf.sprintf("%x",num);console.log(hexStr_native);// 2308249009 as expectedconsole.log(hexStr_sprintfjs);// expecting 2308249009, but get 8249009. Seems only max 4 bytes (32 bit) number allowed, larger than that will be trimmed. I am not aware this lib has this restriction.
Thanks.
Cheers,
Paul
The text was updated successfully, but these errors were encountered:
In doing so, the value is converted to a 32 bits integer. But 150460469257 is greater than the largest 32-bits integer, signed or unsigned, so I guess it overflows.
I don't think I've ever thought of a use for hexadecimal notation beyond representing colors. In such cases 32 bits are sufficient. However, this limitation of the library seems like an unfortunate accident and a bug.
Wouldn't you say it would be better to use Math.abs to ensure the value is positive, instead of introducing features which are particular to C but strange to JS?
Hi all,
Firstly, I like to appreciate the author for this lib. Understand it is the most downloaded lib for this function and has been stable for years.
Maybe I missed out something obvious, can someone in the community tell me what happens here:
Thanks.
Cheers,
Paul
The text was updated successfully, but these errors were encountered: