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

What to do when you need integers larger than 20 digits on mysql?

Big integers aren’t actually limited to 20 digits, they’re limited to the numbers that can be expressed in 64 bits (for example, the number 99,999,999,999,999,999,999 is not a valid big integer despite it being 20 digits long). The reason you have this limitation is that native format integers can be manipulated relatively fast by the … Read more

node.js – Is there any proper way to parse JSON with large numbers? (long, bigint, int64)

Not with built-in JSON.parse. You’ll need to parse it manually and treat values as string (if you want to do arithmetics with them there is bignumber.js) You can use Douglas Crockford JSON.js library as a base for your parser. EDIT2 ( 7 years after original answer ) – it might soon be possible to solve … Read more

Efficient 128-bit addition using carry flag

Actually gcc will use the carry automatically if you write your code carefully… Current GCC can optimize hiWord += (loWord < loAdd); into add/adc (x86’s add-with-carry). This optimization was introduced in GCC5.3. With separate uint64_t chunks in 64-bit mode: https://godbolt.org/z/S2kGRz. And the same thing in 32-bit mode with uint32_t chunks: https://godbolt.org/z/9FC9vc (editor’s note: Of course … Read more

What is the simplest way of implementing bigint in C?

If you’re looking for a simple library, libtommath (from libtomcrypt) is probably what you want. If you’re looking to write a simple implementation yourself (either as a learning exercise or because you only need a very limited subset of bigint functionality and don’t want to tack on a dependency to a large library, namespace pollution, … Read more

BigInteger in C?

Use libgmp: GMP is a free library for arbitrary precision arithmetic, operating on signed integers, rational numbers, and floating-point numbers. There is no practical limit to the precision except the ones implied by the available memory in the machine GMP runs on… Since version 6, GMP is distributed under the dual licenses, GNU LGPL v3 … Read more

tech