From: Rob Biedenharn Date: 2010-08-10T12:13:46+09:00 Subject: Re: Error: Bignum too big to convert into `long' On Aug 9, 2010, at 6:09 PM, Matt Mencel wrote: > Hi, > > I've got a bit of code that I borrowed from here http://www.ruby-forum.com/topic/77821 > . I use it to convert MS timestamps into a ruby Time object. > It works fine on Mac/Linux, but not on a Solaris SPARC system. The > error is "bignum too big to convert into `long'" and it occurs on > the line that begins... > Time.at(.....) > > I'm wondering if it's because SPARC is Big-Endian that I get the > error? > > > def self.ad2time(timestamp) > ad_epoch = 116_444_736_000_000_000 > ad_multiplier = 10_000_000 > > # DEBUG > ap ad_epoch.class > puts "TIMESTAMP: #{timestamp}" > ap timestamp.class > > Time.at((timestamp.to_i - ad_epoch) / ad_multiplier) > end > > > > On my Mac (Snow Leopard x86_64) the DEBUG output looks like this... Ah, note the x86_64 part? That's a 64-bit system so Fixnum holds up to (2^62)-1 > Fixnum < Integer > TIMESTAMP: 9223372036854775807 > Net::BER::BerIdentifiedString < String > > On Solaris SPARC it's this... > Bignum < Integer > TIMESTAMP: 9223372036854775807 > String < Object > > > > Looks like on Solaris it forces the 'ad_epoch' to a Bignum instead > of a Fixnum? Should I try to cast it to a Fixnum on Solaris maybe? > > Matt I suspect your SPARC system is only 32-bit where 2^30 and beyond becomes Bignum. If your timestamp is a Net::BER::BerIdentifiedString, perhaps it has other properties that would help convert it into an Integer. (Notice that both Fixnum and Bignum are subclasses of Integer) On a 32-bit system, the divide between Fixnum and Bignum is: irb> 2**30-1 => 1073741823 irb> _.class => Fixnum irb> 2**30 => 1073741824 irb> _.class => Bignum So 910692730085 is far too big for a Fixnum and Time.at is likely wanting a number of seconds since 1970. Maybe you can see a pattern if you compare Time.now.to_i on your platform with your expected timestamp value. -Rob Rob Biedenharn Rob@AgileConsultingLLC.com http://AgileConsultingLLC.com/ rab@GaslightSoftware.com http://GaslightSoftware.com/