[MacRuby-devel] floats in core data

Laurent Sansonetti lsansonetti at apple.com
Fri Nov 27 12:22:22 PST 2009


Hi John,

This may be a bug in MacRuby, I don't know bindings well enough. It  
would be cool if you could reduce the problem into a small Ruby script.

We are indeed unboxing NSNumbers automatically. NSDecimalNumber seems  
to be left untouched, which could explain why the normal arithmetic  
operators do not work.

Laurent

On Nov 27, 2009, at 7:50 AM, John Shea wrote:

> Hi all,
>
> does any one know whether there is an issue with binding to floats,  
> doubles in core data with macruby?
>
> For example:
>
> 1 I firstly, create an attribute foo which is set as a double or a  
> float in the core data model
> 2. i bind it to a table column
> 3. I set foo to 300.3 in code (not through the user interface)
> 4. it comes through as 1 (or 1.00 if formatted - which is probably  
> neither here nor there)
>
> If i do the same but set the attribute to be of type decimal - then  
> the number 300.3 comes through fine.
>
> The problem then is that is that the class of foo is NSDecimalNumber  
> - and its really painful doing calculations with NSDecimalNumbers  
> given that normal arithmetic operators do not work.
> I haven't found it to be that accurate either (at least in Objective  
> C) - compared to ruby floats.
>
> The strange thing is that both end up (in macruby) inheriting from  
> NSNumber - but somehow the binding cannot make sense of it.
>
> Is it possible that there is a non macruby translation going on? -  
> an unboxing - because the binding/kvc access thinks that foo is a  
> float? (which it might be, in the persistent store - but does not  
> seem to be by the time its accessed).
>
> I can think of work arounds - but i thought i better check with the  
> experts first ;-).
>
> Cheers,
> J
>
> _______________________________________________
> MacRuby-devel mailing list
> MacRuby-devel at lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel



More information about the MacRuby-devel mailing list