OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include <math.h> | 5 #include <math.h> |
6 | 6 |
7 #include "vm/bootstrap_natives.h" | 7 #include "vm/bootstrap_natives.h" |
8 | 8 |
9 #include "vm/bigint_operations.h" | 9 #include "vm/bigint_operations.h" |
10 #include "vm/double_conversion.h" | 10 #include "vm/double_conversion.h" |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 arguments->SetReturn( | 182 arguments->SetReturn( |
183 Bigint::Handle(BigintOperations::NewFromDouble(result))); | 183 Bigint::Handle(BigintOperations::NewFromDouble(result))); |
184 } | 184 } |
185 } | 185 } |
186 | 186 |
187 | 187 |
188 DEFINE_NATIVE_ENTRY(Double_toStringAsFixed, 2) { | 188 DEFINE_NATIVE_ENTRY(Double_toStringAsFixed, 2) { |
189 const Double& arg = Double::CheckedHandle(arguments->At(0)); | 189 const Double& arg = Double::CheckedHandle(arguments->At(0)); |
190 GET_NATIVE_ARGUMENT(Smi, fraction_digits, arguments->At(1)); | 190 GET_NATIVE_ARGUMENT(Smi, fraction_digits, arguments->At(1)); |
191 double d = arg.value(); | 191 double d = arg.value(); |
192 int fraction_digits_value = fraction_digits.Value(); | |
193 String& result = String::Handle(); | 192 String& result = String::Handle(); |
194 bool succeeded = DoubleToStringAsFixed(d, fraction_digits_value, result); | 193 intptr_t fraction_digits_value = fraction_digits.Value(); |
195 if (!succeeded) { | 194 if (0 <= fraction_digits_value && fraction_digits_value <= 20) { |
| 195 result = DoubleToStringAsFixed(d, static_cast<int>(fraction_digits_value)); |
| 196 } |
| 197 if (result.IsNull()) { |
196 GrowableArray<const Object*> args; | 198 GrowableArray<const Object*> args; |
197 args.Add(&String::ZoneHandle(String::New( | 199 args.Add(&String::ZoneHandle(String::New( |
198 "Illegal arguments to double.toStringAsFixed"))); | 200 "Illegal arguments to double.toStringAsFixed"))); |
199 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args); | 201 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args); |
200 } | 202 } |
201 arguments->SetReturn(result); | 203 arguments->SetReturn(result); |
202 } | 204 } |
203 | 205 |
204 | 206 |
205 DEFINE_NATIVE_ENTRY(Double_toStringAsExponential, 2) { | 207 DEFINE_NATIVE_ENTRY(Double_toStringAsExponential, 2) { |
206 UNIMPLEMENTED(); | 208 const Double& arg = Double::CheckedHandle(arguments->At(0)); |
| 209 GET_NATIVE_ARGUMENT(Smi, fraction_digits, arguments->At(1)); |
| 210 double d = arg.value(); |
| 211 String& result = String::Handle(); |
| 212 intptr_t fraction_digits_value = fraction_digits.Value(); |
| 213 if (-1 <= fraction_digits_value && fraction_digits_value <= 20) { |
| 214 result = |
| 215 DoubleToStringAsExponential(d, static_cast<int>(fraction_digits_value)); |
| 216 } |
| 217 if (result.IsNull()) { |
| 218 GrowableArray<const Object*> args; |
| 219 args.Add(&String::ZoneHandle(String::New( |
| 220 "Illegal arguments to double.toStringAsExponential"))); |
| 221 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args); |
| 222 } |
| 223 arguments->SetReturn(result); |
207 } | 224 } |
208 | 225 |
209 | 226 |
210 DEFINE_NATIVE_ENTRY(Double_toStringAsPrecision, 2) { | 227 DEFINE_NATIVE_ENTRY(Double_toStringAsPrecision, 2) { |
211 UNIMPLEMENTED(); | 228 const Double& arg = Double::CheckedHandle(arguments->At(0)); |
| 229 GET_NATIVE_ARGUMENT(Smi, precision, arguments->At(1)); |
| 230 double d = arg.value(); |
| 231 String& result = String::Handle(); |
| 232 intptr_t precision_value = precision.Value(); |
| 233 if (1 <= precision_value && precision_value <= 21) { |
| 234 result = DoubleToStringAsPrecision(d, static_cast<int>(precision_value)); |
| 235 } |
| 236 if (result.IsNull()) { |
| 237 GrowableArray<const Object*> args; |
| 238 args.Add(&String::ZoneHandle(String::New( |
| 239 "Illegal arguments to double.toStringAsPrecision"))); |
| 240 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args); |
| 241 } |
| 242 arguments->SetReturn(result); |
212 } | 243 } |
213 | 244 |
214 | 245 |
215 DEFINE_NATIVE_ENTRY(Double_isInfinite, 1) { | 246 DEFINE_NATIVE_ENTRY(Double_isInfinite, 1) { |
216 const Double& arg = Double::CheckedHandle(arguments->At(0)); | 247 const Double& arg = Double::CheckedHandle(arguments->At(0)); |
217 if (isinf(arg.value())) { | 248 if (isinf(arg.value())) { |
218 arguments->SetReturn(Bool::Handle(Bool::True())); | 249 arguments->SetReturn(Bool::Handle(Bool::True())); |
219 } else { | 250 } else { |
220 arguments->SetReturn(Bool::Handle(Bool::False())); | 251 arguments->SetReturn(Bool::Handle(Bool::False())); |
221 } | 252 } |
(...skipping 17 matching lines...) Expand all Loading... |
239 arguments->SetReturn(Bool::Handle(Bool::True())); | 270 arguments->SetReturn(Bool::Handle(Bool::True())); |
240 } else { | 271 } else { |
241 arguments->SetReturn(Bool::Handle(Bool::False())); | 272 arguments->SetReturn(Bool::Handle(Bool::False())); |
242 } | 273 } |
243 } | 274 } |
244 | 275 |
245 // Add here only functions using/referring to old-style casts. | 276 // Add here only functions using/referring to old-style casts. |
246 | 277 |
247 } // namespace dart | 278 } // namespace dart |
248 | 279 |
OLD | NEW |