| Index: runtime/lib/double.cc
|
| ===================================================================
|
| --- runtime/lib/double.cc (revision 42832)
|
| +++ runtime/lib/double.cc (working copy)
|
| @@ -79,20 +79,13 @@
|
| args.SetAt(0, String::Handle(String::New(error_msg)));
|
| Exceptions::ThrowByType(Exceptions::kUnsupported, args);
|
| }
|
| - // TODO(regis): Should we implement Bigint::NewFromDouble instead?
|
| if ((-1.0 < val) && (val < 1.0)) {
|
| return Smi::New(0);
|
| }
|
| DoubleInternals internals = DoubleInternals(val);
|
| - if (internals.IsSpecial()) {
|
| - const Array& exception_arguments = Array::Handle(Array::New(1));
|
| - exception_arguments.SetAt(
|
| - 0, Object::Handle(String::New("BigintOperations::NewFromDouble")));
|
| - Exceptions::ThrowByType(Exceptions::kInternalError, exception_arguments);
|
| - }
|
| + ASSERT(!internals.IsSpecial()); // Only Infinity and NaN are special.
|
| uint64_t significand = internals.Significand();
|
| intptr_t exponent = internals.Exponent();
|
| - intptr_t sign = internals.Sign();
|
| if (exponent <= 0) {
|
| significand >>= -exponent;
|
| exponent = 0;
|
| @@ -104,37 +97,16 @@
|
| }
|
| // A significand has at most 63 bits (after the shift above).
|
| // The cast to int64_t is hence safe.
|
| + int64_t ival = static_cast<int64_t>(significand);
|
| + if (internals.Sign() < 0) {
|
| + ival = -ival;
|
| + }
|
| if (exponent == 0) {
|
| // The double fits in a Smi or Mint.
|
| - int64_t ival = static_cast<int64_t>(significand);
|
| - if (sign < 0) {
|
| - ival = -ival;
|
| - }
|
| return Integer::New(ival);
|
| }
|
| - // Lookup the factory creating a Bigint from a double.
|
| - const Class& bigint_class =
|
| - Class::Handle(Library::LookupCoreClass(Symbols::_Bigint()));
|
| - ASSERT(!bigint_class.IsNull());
|
| - const Function& factory_method = Function::Handle(
|
| - bigint_class.LookupFactoryAllowPrivate(
|
| - Symbols::_BigintFromDoubleFactory()));
|
| - ASSERT(!factory_method.IsNull());
|
| -
|
| - // Create the argument list.
|
| - const intptr_t kNumArgs = 4;
|
| - const Array& args = Array::Handle(Array::New(kNumArgs));
|
| - // Factories get type arguments.
|
| - args.SetAt(0, Object::null_type_arguments());
|
| - args.SetAt(1, Smi::Handle(Smi::New(sign)));
|
| - args.SetAt(2,
|
| - Integer::Handle(Integer::New(static_cast<int64_t>(significand))));
|
| - args.SetAt(3, Integer::Handle(Integer::New(exponent)));
|
| -
|
| - // Invoke the constructor and return the new object.
|
| Integer& result = Integer::Handle();
|
| - result ^= DartEntry::InvokeFunction(factory_method, args);
|
| - ASSERT(result.IsBigint());
|
| + result = Bigint::NewFromShiftedInt64(ival, exponent);
|
| return result.AsValidInteger();
|
| }
|
|
|
|
|