Why is it that parseInt(8,3) == NaN and parseInt(16,3) == 1?

This is something people trip over all the time, even when they know about it. 🙂 You’re seeing this for the same reason parseInt(“1abc”) returns 1: parseInt stops at the first invalid character and returns whatever it has at that point. If there are no valid characters to parse, it returns NaN. parseInt(8, 3) means … Read more

What is the difference between Int and Integer?

“Integer” is an arbitrary precision type: it will hold any number no matter how big, up to the limit of your machine’s memory…. This means you never have arithmetic overflows. On the other hand it also means your arithmetic is relatively slow. Lisp users may recognise the “bignum” type here. “Int” is the more common … Read more

The maximum value for an int type in Go

https://groups.google.com/group/golang-nuts/msg/71c307e4d73024ce?pli=1 The germane part: Since integer types use two’s complement arithmetic, you can infer the min/max constant values for int and uint. For example, const MaxUint = ^uint(0) const MinUint = 0 const MaxInt = int(MaxUint >> 1) const MinInt = -MaxInt – 1 As per @CarelZA’s comment: uint8 : 0 to 255 uint16 : … Read more

How can I compare two floating point numbers in Bash?

More conveniently This can be done more conveniently using Bash’s numeric context: if (( $(echo “$num1 > $num2” |bc -l) )); then … fi Explanation Piping through the basic calculator command bc returns either 1 or 0. The option -l is equivalent to –mathlib; it loads the standard math library. Enclosing the whole expression between … Read more