numeric
Java For-loop changes numeric result when changing type of loop variable
Actually, your first loop would have int overflow in the calculation of (2 * i + 1) when i is large enough, so I wouldn’t rely on the output of it. The second loop, on the other hand, produces a more correct output, since (2 * j + 1) doesn’t overflow, since it performs long … Read more
SQLite ORDER BY string containing number starting with 0
You can use CAST http://www.sqlite.org/lang_expr.html#castexpr to cast the expression to an Integer. sqlite> CREATE TABLE T (value VARCHAR(2)); sqlite> INSERT INTO T (value) VALUES (’10’); sqlite> INSERT INTO T (value) VALUES (’11’); sqlite> INSERT INTO T (value) VALUES (’12’); sqlite> INSERT INTO T (value) VALUES (’01’); sqlite> INSERT INTO T (value) VALUES (’02’); sqlite> INSERT … Read more
How to get bc to handle numbers in scientific (aka exponential) notation?
Unfortunately, bc doesn’t support scientific notation. However, it can be translated into a format that bc can handle, using extended regex as per POSIX in sed: sed -E ‘s/([+-]?[0-9.]+)[eE]\+?(-?)([0-9]+)/(\1*10^\2\3)/g’ <<<“$value” you can replace the “e” (or “e+”, if the exponent is positive) with “*10^”, which bc will promptly understand. This works even if the exponent … Read more
IsNumeric function in c#
public bool IsNumeric(string value) { return value.All(char.IsNumber); }
Associativity math: (a + b) + c != a + (b + c)
On the range of the double type: double dbl1 = (double.MinValue + double.MaxValue) + double.MaxValue; double dbl2 = double.MinValue + (double.MaxValue + double.MaxValue); The first one is double.MaxValue, the second one is double.Infinity On the precision of the double type: double dbl1 = (double.MinValue + double.MaxValue) + double.Epsilon; double dbl2 = double.MinValue + (double.MaxValue + … Read more
Difference between DECIMAL and NUMERIC
They are the same for almost all purposes. At one time different vendors used different names (NUMERIC/DECIMAL) for almost the same thing. SQL-92 made them the same with one minor difference which can be vendor specific: NUMERIC must be exactly as precise as it is defined — so if you define 4 decimal places to … Read more