• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021-2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16package std.core;
17
18/**
19 * Represents boxed double value and related operations
20 */
21export final class Double extends Floating implements Comparable<Double>, JSONable<Double> {
22    private value: double;
23
24    /**
25     * Constructs a new Double instance with initial value zero
26     *
27     */
28    public constructor() {
29        this.value = 0.0;
30    }
31
32    /**
33     * Constructs a new Double instance with provided initial value
34     *
35     * @param value the initial value
36     *
37     */
38    public constructor(value: double) {
39        this.value = value;
40    }
41
42    /**
43     * Constructs a new Double instance from string
44     *
45     * @param value string that may contain a number
46     */
47    public constructor(value: String) {
48        this.value = Double.numberFromString(value);
49    }
50
51    public constructor(value: BigInt) {
52        this.value = value.doubleValue()
53    }
54
55    /**
56     * Creates a new instance of a Double
57     *
58     * @returns A new Double instance
59     */
60    static $_invoke(): Number {
61        return new Double();
62    }
63
64    /**
65     * Creates a new instance of a Double
66     *
67     * @param value The value to be converted to a number. Can be a string, number, or BigInt (optional).
68     *
69     * @returns A new Double instance
70     */
71    static $_invoke(value: String | Number | BigInt | undefined | null): Number {
72        if (value instanceof String) {
73            return new Double(value as String);
74        } else if (value instanceof Number) {
75            return new Double(value as Number);
76        } else if (value instanceof BigInt) {
77            return new Double(value as BigInt);
78        }
79        if (value === null) {
80            return new Double();
81        }
82        return new Double(NaN);
83    }
84
85    /**
86     * Returns value of this instance as a primitive
87     *
88     * @returns value of this instance
89     * @tag arkts
90     */
91    public unboxed(): double {
92        return this.value;
93    }
94
95    /**
96     * Returns boxed representation of the primitive
97     *
98     * @param value value to box
99     *
100     * @returns boxed value
101     * @tag arkts
102     */
103    public static valueOf(value: double): Double {
104        // TODO(ivan-tyulyandin): caching is possible
105        return new Double(value);
106    }
107
108    /**
109     * Returns boxed representation of the primitive
110     *
111     * @param value value to box
112     *
113     * @returns boxed value
114     */
115    public valueOf(): number {
116        return this.value as number;
117    }
118
119    /**
120     * Minimal value that this type can have as a double
121     * the workarond for libc's double literal parsing bug
122     *
123     */
124    public static readonly MIN_VALUE: double = 4.9e-300 / 1.e+24;
125
126    /**
127     * Maximal value that this type can have as a double
128     *
129     */
130    public static readonly MAX_VALUE: double = 1.7976931348623157e+308;
131
132    /**
133     * Maximal integer value that can be used as a double without loss of precision
134     *
135     */
136    public static readonly MAX_SAFE_INTEGER: double = 9007199254740991;
137
138    /**
139     * Minimal integer value that can be used as a double without loss of precision
140     *
141     */
142    public static readonly MIN_SAFE_INTEGER: double = -9007199254740991;
143
144    /**
145     * Size of this type in bits
146     * @tag arkts
147     */
148    public static readonly BIT_SIZE: byte = 64;
149
150    /**
151     * Size of this type in bytes
152     * @tag arkts
153     */
154    public static readonly BYTE_SIZE: byte = 8;
155
156    /**
157     * Represents the NaN value according to IEEE-754 specification
158     *
159     */
160    public static readonly NaN: double = 0.0 / 0.0;
161
162    /**
163     * Represents the +Infinity value according to IEEE-754 specification
164     *
165     */
166    public static readonly POSITIVE_INFINITY: double = 1.0 / 0.0;
167
168    /**
169     * Represents the -Infinity value according to IEEE-754 specification
170     *
171     */
172    public static readonly NEGATIVE_INFINITY: double = -1.0 / 0.0;
173
174    /**
175     * Number of significant precision bits in this floating type
176     * @tag arkts
177     */
178    public static readonly PRECISION: byte = 53;
179
180    /**
181     * Minimal possible difference between two double values.
182     * For double (IEEE-754 binary64) it is 2^(-52) and its bit representation is 0x3cb0000000000000.
183     * @tag arkts
184     */
185    public static readonly DELTA: double = Double.bitCastFromLong(0x3cb0000000000000);
186
187    /**
188     * Minimal possible difference between two double values
189     *
190     */
191    public static readonly EPSILON: double = Double.DELTA;
192
193
194    /**
195     * Returns value of this instance
196     *
197     * @returns value as byte
198     * @tag arkts
199     */
200    public override toByte(): byte {
201        return this.value.toByte();
202    }
203
204    /**
205     * Returns value of this instance
206     *
207     * @returns value as short
208     * @tag arkts
209     */
210    public override toShort(): short {
211        return this.value.toShort();
212    }
213
214    /**
215     * Returns value of this instance
216     *
217     * @returns value as int
218     * @tag arkts
219     */
220    public override toInt(): int {
221        return this.value.toInt();
222    }
223
224    /**
225     * Returns value of this instance
226     *
227     * @returns value as long
228     * @tag arkts
229     */
230    public override toLong(): long {
231        return this.value.toLong();
232    }
233
234    /**
235     * Returns value of this instance
236     *
237     * @returns value as float
238     * @tag arkts
239     */
240    public override toFloat(): float {
241        return this.value.toFloat();
242    }
243
244    /**
245     * Returns value of this instance
246     *
247     * @returns value as double
248     * @tag arkts
249     */
250    public override toDouble(): double {
251        return this.value;
252    }
253
254    /**
255     * Returns value of this instance
256     *
257     * @returns value as char
258     * @tag arkts
259     */
260    public toChar(): char {
261        return this.value.toChar();
262    }
263
264    /**
265     * Returns the primitive as double value
266     *
267     * @param value value to cast
268     *
269     * @returns casted value
270     */
271    public static toDouble(value: double): double {
272        return value;
273    }
274
275    /**
276     * Returns the primitive as char value
277     *
278     * @param value value to cast
279     *
280     * @returns casted value
281     */
282    public static native toChar(value: double): char;
283
284
285    /**
286     * Returns the primitive as byte value
287     *
288     * @param value value to cast
289     *
290     * @returns casted value
291     */
292    public static native toByte(value: double): byte;
293
294    /**
295     * Returns the primitive as short value
296     *
297     * @param value value to cast
298     *
299     * @returns casted value
300     */
301    public static native toShort(value: double): short;
302
303    /**
304     * Returns the primitive as int value
305     *
306     * @param value value to cast
307     *
308     * @returns casted value
309     */
310    public static native toInt(value: double): int;
311
312    /**
313     * Returns the primitive as long value
314     *
315     * @param value value to cast
316     *
317     * @returns casted value
318     */
319    public static native toLong(value: double): long;
320
321    /**
322     * Returns the primitive as float value
323     *
324     * @param value value to cast
325     *
326     * @returns casted value
327     */
328    public static native toFloat(value: double): float;
329
330    /**
331     * Compares this instance to other Double object
332     * The result is less than 0 if this instance lesser than provided object
333     * 0 if they are equal
334     * and greater than 0 otherwise.
335     *
336     * @param other Double object to compare with
337     *
338     * @returns result of the comparison
339     * @tag arkts
340     */
341    public override compareTo(other: Double): int {
342        return (this.value - other).toInt();
343    }
344
345    /**
346     * toString(d: double, r: int): String -- returns a string representation of d by radix r
347     * @tag arkts
348     */
349    public static native toString(d: double, r: int): String;
350
351    /**
352     * @tag arkts
353     */
354    public static toString(d: double): String {
355        return Double.toString(d, 10);
356    }
357
358    /**
359     * @tag arkts
360     */
361    public toString(r: int): String {
362        return Double.toString(this.value, r);
363    }
364
365    public toString(d: Number): String {
366        return Double.toString(this.value, d.toInt());
367    }
368
369    /**
370     * Converts this object to a string
371     *
372     * @returns result of the conversion
373     *
374     */
375    public override toString(): String {
376        return Double.toString(this.value, 10);
377    }
378
379    /**
380     * Without an argument method returns just toString value
381     *
382     * @returns result of the conversion
383     *
384     */
385    public toLocaleString(): String {
386        return new Intl.NumberFormat().format(this.value)
387    }
388
389    public toLocaleString(locales?: string | Intl.Locale | (string | Intl.Locale)[], options?: Intl.NumberFormatOptions): string {
390        const formatter = new Intl.NumberFormat(intlLocalesToLanguageTags(locales), options)
391        return formatter.format(this.value)
392    }
393
394    /**
395     * Returns a hash code (integer representation) for this instance
396     *
397     * @returns representation of this instance
398     * @tag arkts
399     */
400    public override $_hashCode(): int {
401        return this.toInt();
402    }
403
404    /**
405     * compare(double, double) checks if two doubles are differs no more than by Double.DELTA
406     *
407     * @param lhs left-hand side double for comparison
408     *
409     * @param rhs right-hand side double for comparison
410     *
411     * @returns true if lhs and rhs are equal with respect to Double.DELTA
412     * @tag arkts
413     */
414    public static compare(lhs: double, rhs: double): boolean {
415        return (abs(lhs - rhs) <= Double.DELTA)
416    }
417
418    /**
419    * Checks for equality this instance with provided object, treated as a Double
420    *
421    * @param other object to be checked against
422    *
423    * @returns true if provided object and this instance have same value, false otherwise
424    * Returns false if type of provided object is not the same as this type
425    * @tag arkts
426    */
427    public equals(other: NullishType): boolean {
428        if (this === other) {
429            return true
430        }
431
432        if (!(other instanceof Double)) {
433            return false
434        }
435
436        return this.value == (other as Double).value
437    }
438
439    /**
440     * isNaN(double) checks if double is NaN (not a number)
441     *
442     * @param v the double to test
443     *
444     * @returns true if the argument is NaN
445     *
446     */
447    public static isNaN(v: double): boolean {
448        // IEEE-754 feature
449        return v != v;
450    }
451
452    /**
453     * isNaN() checks if the underlying double is NaN (not a number)
454     *
455     * @returns true if the underlying double is NaN
456     * @tag arkts
457     */
458    public isNaN(): boolean {
459        return Double.isNaN(this.value);
460    }
461
462    /**
463     * isFinite(double) checks if double is a floating point value (not a NaN or infinity)
464     *
465     * @param v the double to test
466     *
467     * @returns true if the argument is a floating point value
468     *
469     */
470    public static isFinite(v: double): boolean {
471        return !(Double.isNaN(v) || (v == Double.POSITIVE_INFINITY) || (v == Double.NEGATIVE_INFINITY));
472    }
473
474    /**
475     * isFinite() checks if the underlying double is a floating point value (not a NaN or infinity)
476     *
477     * @returns true if the underlying double is a floating point value
478     * @tag arkts
479     */
480    public isFinite(): boolean {
481        return Double.isFinite(this.value);
482    }
483
484    /**
485     * Checks if double is similar to an integer value
486     *
487     * @param v the double to test
488     *
489     * @returns true if the argument is similar to an integer value
490     *
491     */
492    public static isInteger(v: double): boolean {
493        // In the language % works as C fmod that differs with IEEE-754 % definition
494        return Double.compare(v % (1.0 as double), 0.0 as double);
495    }
496
497    /**
498     * Checks if the underlying double is similar to an integer value
499     *
500     * @returns true if the underlying double is similar to an integer value
501     * @tag arkts
502     */
503    public isInteger(): boolean {
504        return Double.isInteger(this.value);
505    }
506
507    /**
508     * Checks if double is a safe integer value
509     *
510     * @param v the double to test
511     *
512     * @returns true if the argument is integer ans less than MAX_SAFE_INTEGER
513     *
514     */
515    public static isSafeInteger(v: double): boolean {
516        return Double.isInteger(v) && (abs(v) <= Double.MAX_SAFE_INTEGER);
517    }
518
519    /**
520     * Checks if double is a safe integer value
521     *
522     * @returns true if the underlying double is a safe integer
523     * @tag arkts
524     */
525    public isSafeInteger(): boolean {
526        return Double.isSafeInteger(this.value);
527    }
528
529
530    /**
531     * Performs floating point addition of this instance with provided one, returns the result as new instance
532     *
533     * @param other Right hand side of the addition
534     *
535     * @returns Result of the addition
536     * @tag arkts
537     */
538    public add(other: Double): Double {
539        return Double.valueOf((this.value + other.toDouble()) as double)
540    }
541
542    /**
543     * Performs floating point subtraction of this instance with provided one, returns the result as new instance
544     *
545     * @param other Right hand side of the subtraction
546     *
547     * @returns Result of the subtraction
548     * @tag arkts
549     */
550    public sub(other: Double): Double {
551        return Double.valueOf((this.value - other.toDouble()) as double)
552    }
553
554    /**
555     * Performs floating point multiplication of this instance with provided one, returns the result as new instance
556     *
557     * @param other Right hand side of the multiplication
558     *
559     * @returns Result of the multiplication
560     * @tag arkts
561     */
562    public mul(other: Double): Double {
563        return Double.valueOf((this.value * other.toDouble()) as double)
564    }
565
566    /**
567     * Performs floating point division of this instance with provided one, returns the result as new instance
568     *
569     * @param other Right hand side of the division
570     *
571     * @returns Result of the division
572     * @tag arkts
573     */
574    public div(other: Double): Double {
575        return Double.valueOf((this.value / other.toDouble()) as double)
576    }
577
578    /**
579     * Checks if this instance value is less than value of provided instance
580     *
581     * @param other Right hand side of the comparison
582     *
583     * @returns true if this value is less than provided, false otherwise
584     * @tag arkts
585     */
586    public isLessThan(other: Double): boolean {
587        return this.value < other.toDouble();
588    }
589
590    /**
591     * Checks if this instance value is less than or equal to value of provided instance
592     *
593     * @param other Right hand side of the comparison
594     *
595     * @returns true if this value is less than or equal to provided, false otherwise
596     * @tag arkts
597     */
598    public isLessEqualThan(other: Double): boolean {
599        return this.value <= other.toDouble();
600    }
601
602    /**
603     * Checks if this instance value is greater than value of provided instance
604     *
605     * @param other Right hand side of the comparison
606     *
607     * @returns true if this value is greater than provided, false otherwise
608     * @tag arkts
609     */
610    public isGreaterThan(other: Double): boolean {
611        return this.value > other.toDouble();
612    }
613
614    /**
615     * Checks if this instance value is greater than or equal to value of provided instance
616     *
617     * @param other Right hand side of the comparison
618     *
619     * @returns true if this value is greater than or equal to provided, false otherwise
620     * @tag arkts
621     */
622    public isGreaterEqualThan(other: Double): boolean {
623        return this.value >= other.toDouble();
624    }
625
626    /**
627     * parseFloat(String) converts std.core.String to double
628     *
629     * @param s the string to convert
630     *
631     * @returns the result of conversion
632     *
633     * @note
634     * If arg is "+Infinity", "Infinity" or "-Infinity", return value is `inf` or `-inf` respectively.
635     * If arg is "+0" or "-0", return value is 0 or -0.
636     * If arg has leading zeroes, it's ignored: "0001.5" -> 1.5, "-0001.5" -> -1.5
637     * If arg starts from ".", leading zero is implied: ".5" -> 0.5, "-.5" -> -0.5
638     * If arg successfully parsed, trailing non-digits ignored: "-.6ffg" -> -0.6
639     * If arg can not be parsed into a number, NaN is returned
640     *
641     * @remark
642     * Implemented as native function,  @see `parseFloat()` intrinsic [declaration](https://gitee.com/openharmony-sig/arkcompiler_runtime_core/blob/master/plugins/ets/runtime/ets_libbase_runtime.yaml#653).
643     *
644     * ECMA reference: https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-number.parsefloat
645     *
646    */
647    public static native parseFloat(s: String): double;
648
649    /**
650     * parseInt(String, int) parses from String an integer of specified radix
651     *
652     * @param s the string to convert
653     * @param r the radix of conversion; should be [2, 36]; 0 assumed to be 10
654     *
655     * @returns the result of parsing
656     *
657     * @note
658     * If args ("10", 1) -> thrown ArgumentOutOfRangeException, ("10", 37) -> thrown ArgumentOutOfRangeException
659     * If args ("10", 2) -> 2
660     * If args ("10", 10) -> 10, ("10", 0) -> 10
661     * If args ("ff", 16) -> 255
662     * etc.
663     *
664     * @remark
665     * Implemented as native function,  @see `parseInt()` intrinsic [declaration](https://gitee.com/openharmony-sig/arkcompiler_runtime_core/blob/master/plugins/ets/runtime/ets_libbase_runtime.yaml#663).
666     *
667     * ECMA reference: https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-number.parseint
668     *
669    */
670    public static native parseIntCore(s: String, r: int): double;
671
672    /**
673     * parseInt(String, int) parses from String an integer of specified radix
674     *
675     * @param s the string to convert
676     * @param r the radix of conversion; should be [2, 36]; 0 assumed to be 10
677     *
678     * @returns the result of parsing
679     *
680     * @note
681     * If args ("10", 1) -> thrown ArgumentOutOfRangeException, ("10", 37) -> thrown ArgumentOutOfRangeException
682     * If args ("10", 2) -> 2
683     * If args ("10", 10) -> 10, ("10", 0) -> 10
684     * If args ("ff", 16) -> 255
685     * etc.
686     *
687     * @remark
688     * Implemented as native function,  @see `parseInt()` intrinsic [declaration](https://gitee.com/openharmony-sig/arkcompiler_runtime_core/blob/master/plugins/ets/runtime/ets_libbase_runtime.yaml#663).
689     *
690     * ECMA reference: https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-number.parseint
691     *
692    */
693    public static parseInt(s: String, r: double): double {
694        if (!Double.isFinite(r)) {
695            r = 0.0;
696        }
697        if ((r < 2.0 || r > 36.0) && r != 0.0) {
698            return NaN;
699        } else {
700            return Double.parseIntCore(s.trim(), Double.toInt(r));
701        }
702    }
703
704    /**
705     * parseInt(String, int) parses from String an integer of specified radix
706     *
707     * @param s the string to convert
708     * @param r the radix of conversion; should be [2, 36]; 0 assumed to be 10
709     *
710     * @returns the result of parsing
711     *
712     * @note
713     * If args ("10", 1) -> thrown ArgumentOutOfRangeException, ("10", 37) -> thrown ArgumentOutOfRangeException
714     * If args ("10", 2) -> 2
715     * If args ("10", 10) -> 10, ("10", 0) -> 10
716     * If args ("ff", 16) -> 255
717     * etc.
718     *
719     * @remark
720     * Implemented as native function,  @see `parseInt()` intrinsic [declaration](https://gitee.com/openharmony-sig/arkcompiler_runtime_core/blob/master/plugins/ets/runtime/ets_libbase_runtime.yaml#663).
721     *
722     * ECMA reference: https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-number.parseint
723     *
724    */
725    public static parseInt(s: String, r: int): double {
726        if ((r < 2 || r > 36) && r != 0.0) {
727            return NaN;
728        } else {
729            return Double.parseIntCore(s, r);
730        }
731    }
732
733    /**
734     * parseInt(String) parses from String an integer of radix 10
735     *
736     * @param s the string to convert
737     *
738     * @returns the result of parsing
739     *
740    */
741    public static parseInt(s: String): double {
742        return Double.parseIntCore(s, -1 as int);
743    }
744
745    /**
746     * toExponential(double) returns std.core.String representing the underlying double in exponential notation
747     *
748     * @param d the exponent (rounded to nearest integer); must be in [0, 100]
749     *
750     * @returns the result of conversion
751     *
752     * @note
753     * If d = new Double(0.25); d.toExponential(2) -> "2.50e-1"
754     * If d = new Double(0.25); d.toExponential(2.5) -> "2.50e-1"
755     * If d = new Double(0.25); d.toExponential(1) -> "2.5e-1"
756     * If d = new Double(12345.01); d.toExponential(10) -> "1.2345010000e+4"
757     * If d = new Double(NaN); d.toExponential(10) -> "NaN";
758     * If d = new Double(Double.POSITIVE_INFINITY); d.toExponential(10) -> "Infinity";
759     *                                                                     "-Infinity" for negative
760     *
761     * @remark
762     * Implemented as native function,  @see `toExponential()` intrinsic [declaration](https://gitee.com/openharmony-sig/arkcompiler_runtime_core/blob/master/plugins/ets/runtime/ets_libbase_runtime.yaml#673).
763     *
764     * ECMA reference: https://tc39.es/ecma262/multipage/doubles-and-dates.html#sec-double.prototype.toexponential
765     *
766    */
767    public native toExponential(d: double): String;
768    public native toExponentialWithNoDigit(): String;
769
770    /**
771     * toExponential() returns std.core.String representing the underlying double in exponential notation
772     *
773     * @returns the result of conversion
774     *
775    */
776    public toExponential(): String {
777        return this.toExponentialWithNoDigit();
778    }
779
780    /**
781     * toPrecision(double) returns std.core.String representing the underlying double on the specified precision
782     *
783     * @param d precision (rounded to nearest integer); must be in [1, 100]
784     *
785     * @returns the result of conversion
786     *
787     * @note
788     * If d = new Double(0.25); d.toPrecision(4) -> "0.2500"
789     * If d = new Double(1.01); d.toPrecision(4.7) -> "1.010"
790     * If d = new Double(0.25); d.toPrecision(0) -> thrown ArgumentOutOfRangeException
791     * If d = new Double(12345.123455); d.toPrecision(10) -> "12345.12346"
792     *
793     * @remark
794     * Implemented as native function,  @see `toPrecision()` intrinsic [declaration](https://gitee.com/openharmony-sig/arkcompiler_runtime_core/blob/master/plugins/ets/runtime/ets_libbase_runtime.yaml#683).
795     *
796     * ECMA reference: https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-number.prototype.toprecision
797     *
798    */
799    public native toPrecision(d: double): String;
800
801    /**
802     * toPrecision() returns std.core.String representing the underlying double in exponential notation
803     *                       basically, if toPrecision called with no argument it's just toString according
804     *                       to spec
805     *
806     * @returns the result of conversion
807     *
808    */
809    public toPrecision(): String {
810        return this.toString();
811    }
812
813    /**
814     * toFixed(double) returns std.core.String representing the underlying double using fixed-point notation
815     *
816     * @param d fixed size (integer part); must be in [0, 100]
817     *
818     * @returns the result of conversion
819     *
820     * @note
821     * If d = new Double(0.1); d.toFixed(0) -> "0"
822     * If d = new Double(0.7); d.toFixed(0) -> "1"
823     * If d = new Double(0.12345); d.toFixed(1) -> "0.1"
824     * If d = new Double(0.12345); d.toFixed(3) -> "0.123"
825     * If d = new Double(Double.POSITIVE_INFINITY); d.toFixed(3) -> "Infinity"
826     * If d = new Double(Double.NaN); d.toFixed(3) -> "NaN"
827     * If d = new Double(0.25); d.toFixed(200) -> thrown ArgumentOutOfRangeException
828     *
829     * @remark
830     * Implemented as native function,  @see `toFixed()` intrinsic [declaration](https://gitee.com/openharmony-sig/arkcompiler_runtime_core/blob/master/plugins/ets/runtime/ets_libbase_runtime.yaml#693).
831     *
832     * ECMA reference: https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-number.prototype.tofixed
833     *
834    */
835    public native toFixed(d: double): String;
836
837    /**
838     * toFixed(double) returns std.core.String representing the underlying double using fixed-point notation
839     *
840     * @returns the result of conversion
841     *
842    */
843    public toFixed(): String {
844        return this.toFixed(0);
845    }
846
847    /**
848     * Converts bit representation to corresponding IEEE-754 floating point representation
849     * @param bits bits to convert
850     *
851     * @returns double - converted value
852     * @tag arkts
853     */
854    public static native bitCastFromLong(bits: long): double
855
856    /**
857     * Converts IEEE-754 floating point representation to corresponding bit representation
858     * @param val value to convert
859     *
860     * @returns long - bit representation
861     * @tag arkts
862     */
863    public static native bitCastToLong(val: double): long
864
865    /**
866     * Creates a Double instance based on JSONValue
867     *
868     * @param json: JSONValue - a JSON representation
869     *
870     * @throws JSONTypeError if json does not encode a valid double
871     *
872     * @returns Double - double value decoded from JSON
873     * @tag arkts
874     */
875    public createFromJSONValue(json: JSONValue): Double {
876        if (json instanceof JSONNumber) {
877            return Double.valueOf((json as JSONNumber).value)
878        }
879        throw new JSONTypeError("Cannot create Double from JSON", new ErrorOptions(json as Object))
880    }
881
882
883    /**
884     * numberFromString(String) converts std.core.String to double
885     *
886     * @param s the string to convert
887     *
888     * @returns the result of conversion
889     *
890     * @note
891     * If arg is "+Infinity", "Infinity" or "-Infinity", return value is `inf` or `-inf` respectively.
892     * If arg is "+0" or "-0", return value is 0 or -0.
893     * If arg has leading zeroes, it's ignored: "0001.5" -> 1.5, "-0001.5" -> -1.5
894     * If arg starts from ".", leading zero is implied: ".5" -> 0.5, "-.5" -> -0.5
895     * If arg successfully parsed, trailing non-digits cause return value is NaN: "-.6ffg" -> -NaN
896     * If arg can not be parsed into a number, NaN is returned
897     *
898     *
899     * ECMA reference: https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-number-constructor-number-value
900     */
901    private static native numberFromString(s: String): double;
902}
903