Wrong result by Java Math.pow

You’ve exceeded the number of significant digits available (~15 to 16) in double-precision floating-point values. Once you do that, you can’t expect the least significant digit(s) of your result to actually be meaningful/precise. If you need arbitrarily precise arithmetic in Java, consider using BigInteger and BigDecimal.

Subtracting long numbers in javascript

Because numbers in JavaScript are floating-point. They have limited precision. When JavaScript sees a very long number, it rounds it to the nearest number it can represent as a 64-bit float. In your script, start and end get rounded to the same value. alert(1234567890123456789); // says: 1234567890123456800 alert(1234567890123456799); // says: 1234567890123456800 There’s no built-in way … Read more

Generate random values in C#

This should do the trick. (It’s an extension method so that you can call it just as you call the normal Next or NextDouble methods on a Random object). public static Int64 NextInt64(this Random rnd) { var buffer = new byte[sizeof(Int64)]; rnd.NextBytes(buffer); return BitConverter.ToInt64(buffer, 0); } Just replace Int64 with UInt64 everywhere if you want … Read more

How to use long id in Rails applications?

Credits to http://moeffju.net/blog/using-bigint-columns-in-rails-migrations class CreateDemo < ActiveRecord::Migration def self.up create_table :demo, :id => false do |t| t.integer :id, :limit => 8 end end end See the option :id => false which disables the automatic creation of the id field The t.integer :id, :limit => 8 line will produce a 64 bit integer field