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

How to printf long long

%lld is the standard C99 way, but that doesn’t work on the compiler that I’m using (mingw32-gcc v4.6.0). The way to do it on this compiler is: %I64d So try this: if(e%n==0)printf(“%15I64d -> %1.16I64d\n”,e, 4*pi); and scanf(“%I64d”, &n); The only way I know of for doing this in a completely portable way is to use … Read more

How to convert a String to long in javascript?

JavaScript has a Number type which is a 64 bit floating point number*. If you’re looking to convert a string to a number, use either parseInt or parseFloat. If using parseInt, I’d recommend always passing the radix too. use the Unary + operator e.g. +”123456″ use the Number constructor e.g. var n = Number(“12343”) *there … Read more

C: Casting minimum 32-bit integer (-2147483648) to float gives positive number (2147483648.0)

Replace #define INT32_MIN (-2147483648L) with #define INT32_MIN (-2147483647 – 1) -2147483648 is interpreted by the compiler to be the negation of 2147483648, which causes overflow on an int. So you should write (-2147483647 – 1) instead. This is all C89 standard though. See Steve Jessop’s answer for C99. Also long is typically 32 bits on … Read more

Definition of int64_t

a) Can you explain to me the difference between int64_t and long (long int)? In my understanding, both are 64 bit integers. Is there any reason to choose one over the other? The former is a signed integer type with exactly 64 bits. The latter is a signed integer type with at least 32 bits. … Read more