summaryrefslogtreecommitdiff
path: root/scripting
diff options
context:
space:
mode:
authorAaron <aaron@10gen.com>2010-03-01 09:26:35 -0800
committerAaron <aaron@10gen.com>2010-03-01 09:26:35 -0800
commit89f3e6d65b0d0daa5e70a9dc97a60297ed167678 (patch)
treee5ec78078f679f106cb5e8595beac09cb5163b89 /scripting
parent45d3cfbfcf6176d70f7ea4be7b136eb1213f0c4a (diff)
downloadmongo-89f3e6d65b0d0daa5e70a9dc97a60297ed167678.tar.gz
SERVER-677 add floatApprox sm
Diffstat (limited to 'scripting')
-rw-r--r--scripting/engine_spidermonkey.cpp22
1 files changed, 15 insertions, 7 deletions
diff --git a/scripting/engine_spidermonkey.cpp b/scripting/engine_spidermonkey.cpp
index 294431c6e35..51ba1ca1c4f 100644
--- a/scripting/engine_spidermonkey.cpp
+++ b/scripting/engine_spidermonkey.cpp
@@ -160,9 +160,14 @@ namespace mongo {
// NOTE No validation of passed in object
long long toNumberLongUnsafe( JSObject *o ) {
- boost::uint64_t val =
- ( (boost::uint64_t)(boost::uint32_t)getNumber( o , "top" ) << 32 ) +
- ( boost::uint32_t)( getNumber( o , "bottom" ) );
+ boost::uint64_t val;
+ if ( hasProperty( o, "top" ) ) {
+ val =
+ ( (boost::uint64_t)(boost::uint32_t)getNumber( o , "top" ) << 32 ) +
+ ( boost::uint32_t)( getNumber( o , "bottom" ) );
+ } else {
+ val = getNumber( o, "floatApprox" );
+ }
return val;
}
@@ -566,10 +571,13 @@ namespace mongo {
case NumberLong: {
boost::uint64_t val = (boost::uint64_t)e.numberLong();
JSObject * o = JS_NewObject( _context , &numberlong_class , 0 , 0 );
- // using 2 doubles here instead of a single double because certain double
- // bit patterns represent undefined values and sm might trash them
- setProperty( o , "top" , toval( (double)(boost::uint32_t)( val >> 32 ) ) );
- setProperty( o , "bottom" , toval( (double)(boost::uint32_t)( val & 0x00000000ffffffff ) ) );
+ setProperty( o , "floatApprox" , toval( (double)(boost::int64_t)( val ) ) );
+ if ( val != boost::uint64_t( double( val ) ) ) {
+ // using 2 doubles here instead of a single double because certain double
+ // bit patterns represent undefined values and sm might trash them
+ setProperty( o , "top" , toval( (double)(boost::uint32_t)( val >> 32 ) ) );
+ setProperty( o , "bottom" , toval( (double)(boost::uint32_t)( val & 0x00000000ffffffff ) ) );
+ }
return OBJECT_TO_JSVAL( o );
}
case DBRef: {