After further investigation, I have found that the "to_f" method in my 32 bit 
build has problems.

My simple test case, I created a new MacRuby project in the latest XCode.

1. Modified the Valid Archetectures to "i386 x86_64"
2. Added the following snippet of code to rb_main.rb

NSLog( "In rb_main.rb")

i = 1296445544
puts "i = %d class = %s" % [i, i.class.to_s]

f = i.to_f
puts "f = %f class = %@ DIG = %d" % [ f, f.class, Float::DIG.to_s]

if i == f
  puts "Is equal"
else
  puts "Not equal"
end

time = Time.new
puts "time = %s" % [time.to_s]
puts "time to_i = %d" % [time.to_i]
puts "time to_f = %f" % [time.to_f]

3. Modified the Architecture to "64 Bit Intel" or  "Standard (32/64bit 
Universal)". Ran the code and got this.

2011-01-30 22:17:19.694 TestFloat[15654:a0f] In rb_main.rb
i = 1296445544 class = Fixnum
f = 1296445544.000000 class = Float DIG = 15
Is equal
time = 2011-01-30 22:17:19 -0600
time to_i = 1296447439
time to_f = 1296447439.697984

3. Modified the Architecture to "32 Bit Universal". Ran the code and got this.

2011-01-30 22:20:47.891 TestFloat[15685:a0f] +[NSATSGlyphGenerator initialize] 
invocation.  The class is deprecated.
2011-01-30 22:20:49.317 TestFloat[15685:a0f] In rb_main.rb
i = 1296445544 class = Bignum
f = 1296445440.000000 class = Float DIG = 15
Not equal
time = 2011-01-30 22:20:49 -0600
time to_i = 1296447649
time to_f = 1296447488.000000

You will notice how the floating point representation has lost a lot of
precision in the 32 bit version which is understandable in a much larger number
but this number is 10 digits and not 15 digits. 

This creates big problems when dealing with anything that is dealing with 
NSDate such
as NSCalendar, NSDatePicker, NSTimer, etc

You can also reproduce the problem by click the 32 bit button on the Get Info 
of the 32/64 bit universal version

I hope that i am missing something obvious.

Please help!

On Jan 28, 2011, at 9:00 AM, macruby-devel-requ...@lists.macosforge.org wrote:
> 
> Message: 3
> Date: Fri, 28 Jan 2011 06:02:23 -0600
> From: Richard Sepulveda <rsepulve...@gmail.com>
> To: macruby-devel@lists.macosforge.org
> Subject: [MacRuby-devel] Strange NSDate behavior building 32 bit v 64
>       bit
> Message-ID: <1258938a-1f77-4150-beab-05cd2045d...@gmail.com>
> Content-Type: text/plain; charset="us-ascii"
> 
> I am seeing some strange behavior with NSDate, here is my basic code in a new 
> MacRuby project.
> 
> I am running on a MacBook 2009 model, Mac OSX 10.6.6
> 
> I am using the latest XCode and the MacRuby Framework 0.7 in XCode 
> 
> in rbmain.rb:
> 
> NSLog("In rb_main.rb")
> puts "NSDate = " + NSDate.date.to_s
> NSLog( "NSDate = " + NSDate.date.to_s)
> 
> CCode.printNSDate
> 
> in CCode.m:
> 
> @implementation CCode
> 
>  + (void) printNSDate
>  {
>    NSLog(@"In printNSDate, NSDate = %@", NSDate.date);
>  }
> 
> @end
> 
> When compiled: 64-bit Universal, the output is
> 
> 2011-01-28 05:54:16.972 TestRuby[90066:a0f] In rb_main.rb
> NSDate = 2011-01-28 05:54:16 -0600
> 2011-01-28 05:54:16.976 TestRuby[90066:a0f] NSDate = 2011-01-28 05:54:16 -0600
> 2011-01-28 05:54:16.979 TestRuby[90066:a0f] In printNSDate, NSDate = 
> 2011-01-28 05:54:16 -0600
> 
> When compiled: 32-bit Universal, the output is
> 
> 2011-01-28 05:51:23.941 TestRuby[89998:a0f] In rb_main.rb
> NSDate = 2011-01-28 05:44:00 -0600
> 2011-01-28 05:51:23.958 TestRuby[89998:a0f] NSDate = 2011-01-28 05:44:00 -0600
> 2011-01-28 05:51:23.961 TestRuby[89998:a0f] In printNSDate, NSDate = 
> 2011-01-28 05:51:23 -0600
> 2011-01-28 05:51:24.565 TestRuby[89998:a0f] Error loading 
> /Library/InputManagers/Smart Crash Reports/Smart Crash 
> Reports.bundle/Contents/MacOS/Smart Crash Reports:  
> dlopen(/Library/InputManagers/Smart Crash Reports/Smart Crash 
> Reports.bundle/Contents/MacOS/Smart Crash Reports, 265): no suitable image 
> found.  Did find:
>       /Library/InputManagers/Smart Crash Reports/Smart Crash 
> Reports.bundle/Contents/MacOS/Smart Crash Reports: GC capability mismatch
> 2011-01-28 05:51:25.409 TestRuby[89998:a0f] Error loading 
> /Library/InputManagers/SIMBL/SIMBL.bundle/Contents/MacOS/SIMBL:  
> dlopen(/Library/InputManagers/SIMBL/SIMBL.bundle/Contents/MacOS/SIMBL, 265): 
> no suitable image found.  Did find:
>       /Library/InputManagers/SIMBL/SIMBL.bundle/Contents/MacOS/SIMBL: GC 
> capability mismatch
> 
> 
> The Obj-C routine prints the correct time. 5:51:23 in both cases.
> For 32 bit, the Ruby code prints some time in the past that never changes.
> For 64 bit, the Ruby code prints the correct time.
> 
> Any idea's what could be going on?

_______________________________________________
MacRuby-devel mailing list
MacRuby-devel@lists.macosforge.org
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel

Reply via email to