Forum BigDB double/float returning NaN

Discussion and help relating to the PlayerIO database solution, BigDB.

double/float returning NaN

Postby stevewoolcock » August 25th, 2011, 2:17 am

Hey all,

I have a double stored in my BigDB (under a PlayerObject), which is being returned as NaN when the player object is loaded into my Flash application. You can see in the attached screenshot that data type is definitely a Double, however when I output the object after loading into Actionscript, it returns a NaN value. This happens even if I convert the data type to a float within the database.

Both double and float are support via Actionscript using the Number class, so I'm not sure what's happening here. Converting to an Int or UInt works fine.

Code: Select all
data:{
   level:NaN
}      


I've even tried creating a brand new property and assigning it a float or double value of 0.0. Both return NaN. Any ideas as to what's happening here?

Cheers
Attachments
Untitled-2.jpg
Untitled-2.jpg (19.13 KiB) Viewed 20524 times
stevewoolcock
 
Posts: 7
Joined: August 9th, 2011, 2:36 pm

Re: double/float returning NaN

Postby stevewoolcock » August 25th, 2011, 2:22 am

On further inspection (actually, just after posting this), it appears that the value of 0 (or 0.0, etc) is the problem. When stored in BigDB as a float or double, the Actionscript API seems to return NaN. If I change the values to 1, 0.5, 1.5, etc, the values are returned as expected.

This seems like strange behaviour to me. Is this a bug with the DatabaseObject parser in the PlayerIO API?
stevewoolcock
 
Posts: 7
Joined: August 9th, 2011, 2:36 pm

Re: double/float returning NaN

Postby Benjaminsen » August 25th, 2011, 2:26 am

[Disregard my previous comment I mixed up doubles and longs]

It should work, I just tested it with great success. I am investigating further.
Benjaminsen
.IO
 
Posts: 1444
Joined: January 12th, 2010, 11:54 am
Location: Denmark

Re: double/float returning NaN

Postby stevewoolcock » August 25th, 2011, 2:34 am

Thank you for the quick reply. Did you try a Double and Float with a value of 0? This appears to be the problem for me. I can't for the life of me work out why this is happening...
stevewoolcock
 
Posts: 7
Joined: August 9th, 2011, 2:36 pm

Re: double/float returning NaN

Postby Benjaminsen » August 25th, 2011, 2:39 am

It's not 100% impossible that we deserialize the 0 case wrong inside the API

A quick fix while we investigate and possible release a patch is to read the data as follows:

var myfloat = object.floatid || 0
Benjaminsen
.IO
 
Posts: 1444
Joined: January 12th, 2010, 11:54 am
Location: Denmark

Re: double/float returning NaN

Postby stevewoolcock » August 25th, 2011, 2:43 am

Thanks for looking into the problem and for the work around. I can implement it, although I was using anonymous/generic objects directly from the deserialized DatabaseObject data, so I didn't know exactly what properties to expect. But I can work with it fore now.

I await the results of your investigation!
stevewoolcock
 
Posts: 7
Joined: August 9th, 2011, 2:36 pm

Re: double/float returning NaN

Postby jett_way » February 24th, 2012, 7:07 pm

This is still happening. Seems like an important thing to fix because it can easily result in corrupted data. If you have a DatabaseObject, returned from BigDB, that has zero-value floating-point number properties (which are returned as NaN), when you call save() on the object, NaN is written as the new (corrupt) value of all those properties.
jett_way
 
Posts: 16
Joined: June 9th, 2011, 10:42 pm

Re: double/float returning NaN

Postby FulaFisken » March 5th, 2012, 2:42 pm

This is happening for us too. We have NAN issues with doubles stored as 0 in BigDB.
Fula Fisken
website blog twitter
Play Game
Astroflux
User avatar
FulaFisken
Paid Member
 
Posts: 139
Joined: March 2nd, 2011, 10:15 am

Re: double/float returning NaN

Postby Benjaminsen » March 8th, 2012, 9:54 pm

We fixed the bug in the API, we expect to have it released next week. Stay tuned!
Benjaminsen
.IO
 
Posts: 1444
Joined: January 12th, 2010, 11:54 am
Location: Denmark

Re: double/float returning NaN

Postby jett_way » March 14th, 2012, 6:08 pm

That's great news! Thanks for getting it fixed!

Now... if we could just have a way to handle number types more explicitly. Most likely because all numbers in AS3 are Numbers under the hood ("is" operator always returns Number), it can be difficult to keep numbers stored in BigDB in the right format. You can easily end up with int when you wanted a float (which you would have to settle for double anyway). It would be very useful to specify value types when creating database objects from AS3. Something like AddFloat(), AddUint(), etc.
jett_way
 
Posts: 16
Joined: June 9th, 2011, 10:42 pm


Return to BigDB