summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron <aaron@10gen.com>2011-04-19 15:15:51 -0700
committerAaron <aaron@10gen.com>2011-04-19 15:16:08 -0700
commit7d1b34670099329c8dac435219d5c6050b0b72b3 (patch)
tree0b3d3a805c672b97bbbbb2bb8577caff06759733
parentf8cb1e292c1e7e80ba5627468705cbf0130c82af (diff)
downloadmongo-7d1b34670099329c8dac435219d5c6050b0b72b3.tar.gz
make NumberLong floatApprox casts more incremental - some compilers may have been optimizing them out
-rw-r--r--scripting/engine_spidermonkey.cpp5
-rw-r--r--scripting/v8_wrapper.cpp7
2 files changed, 7 insertions, 5 deletions
diff --git a/scripting/engine_spidermonkey.cpp b/scripting/engine_spidermonkey.cpp
index 73ebfaa55da..b455145568e 100644
--- a/scripting/engine_spidermonkey.cpp
+++ b/scripting/engine_spidermonkey.cpp
@@ -551,8 +551,9 @@ namespace mongo {
void makeLongObj( long long n, JSObject * o ) {
boost::uint64_t val = (boost::uint64_t)n;
CHECKNEWOBJECT(o,_context,"NumberLong1");
- setProperty( o , "floatApprox" , toval( (double)(boost::int64_t)( val ) ) );
- if ( (boost::int64_t)val != (boost::int64_t)(double)(boost::int64_t)( val ) ) {
+ double floatApprox = (double)(boost::int64_t)val;
+ setProperty( o , "floatApprox" , toval( floatApprox ) );
+ if ( (boost::int64_t)val != (boost::int64_t)floatApprox ) {
// 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 ) ) );
diff --git a/scripting/v8_wrapper.cpp b/scripting/v8_wrapper.cpp
index ff67e8cf953..54a6674fa96 100644
--- a/scripting/v8_wrapper.cpp
+++ b/scripting/v8_wrapper.cpp
@@ -217,14 +217,15 @@ namespace mongo {
Local<v8::Object> sub = readOnly ? readOnlyObjects->NewInstance() : internalFieldObjects->NewInstance();
unsigned long long val = f.numberLong();
v8::Function* numberLong = getNamedCons( "NumberLong" );
- if ( (long long)val == (long long)(double)(long long)(val) ) {
+ double floatApprox = (double)(long long)val;
+ if ( (long long)val == (long long)floatApprox ) {
v8::Handle<v8::Value> argv[1];
- argv[0] = v8::Number::New( (double)(long long)( val ) );
+ argv[0] = v8::Number::New( floatApprox );
o->Set( v8::String::New( f.fieldName() ), numberLong->NewInstance( 1, argv ) );
}
else {
v8::Handle<v8::Value> argv[3];
- argv[0] = v8::Number::New( (double)(long long)(val) );
+ argv[0] = v8::Number::New( floatApprox );
argv[1] = v8::Integer::New( val >> 32 );
argv[2] = v8::Integer::New( (unsigned long)(val & 0x00000000ffffffff) );
o->Set( v8::String::New( f.fieldName() ), numberLong->NewInstance(3, argv) );