Javascript long integer

In Java, you have 64 bits integers, and that’s what you’re using. In JavaScript, all numbers are 64 bits floating point numbers. This means you can’t represent in JavaScript all the Java longs. The size of the mantissa is about 53 bits, which means that your number, 793548328091516928, can’t be exactly represented as a JavaScript … Read more

Convert integers to written numbers

This should work reasonably well: public static class HumanFriendlyInteger { static string[] ones = new string[] { “”, “One”, “Two”, “Three”, “Four”, “Five”, “Six”, “Seven”, “Eight”, “Nine” }; static string[] teens = new string[] { “Ten”, “Eleven”, “Twelve”, “Thirteen”, “Fourteen”, “Fifteen”, “Sixteen”, “Seventeen”, “Eighteen”, “Nineteen” }; static string[] tens = new string[] { “Twenty”, “Thirty”, … Read more

Python: why does `random.randint(a, b)` return a range inclusive of `b`?

I tried to get to the bottom of this by examining some old sources. I suspected that randint was implemented before Python’s long integer: meaning that if you wanted a random number that included INT_MAX, you would have needed to call random.randrange(0, INT_MAX + 1) which would have overflowed and resulted in arguments of (0, … Read more

string = string + int: What’s behind the scenes?

It compiles to a call to String.Concat(object, object), like this: string sth = String.Concat(“something”, 0); (Note that this particular line will actually be optimized away by the compiler) This method is defined as follows: (Taken from the .Net Reference Source) public static String Concat(Object arg0, Object arg1) { if (arg0==null) { arg0 = String.Empty; } … Read more