2
0

NumberInstance.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using System;
  2. using System.Runtime.CompilerServices;
  3. using Jint.Native.Object;
  4. using Jint.Runtime;
  5. namespace Jint.Native.Number
  6. {
  7. public class NumberInstance : ObjectInstance, IPrimitiveInstance
  8. {
  9. private static readonly long NegativeZeroBits = BitConverter.DoubleToInt64Bits(-0.0);
  10. public NumberInstance(Engine engine)
  11. : base(engine, ObjectClass.Number)
  12. {
  13. }
  14. public NumberInstance(Engine engine, JsNumber value)
  15. : base(engine, ObjectClass.Number)
  16. {
  17. NumberData = value;
  18. }
  19. Types IPrimitiveInstance.Type => Types.Number;
  20. JsValue IPrimitiveInstance.PrimitiveValue => NumberData;
  21. public JsNumber NumberData { get; set; }
  22. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  23. public static bool IsNegativeZero(double x)
  24. {
  25. return x == 0 && BitConverter.DoubleToInt64Bits(x) == NegativeZeroBits;
  26. }
  27. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  28. public static bool IsPositiveZero(double x)
  29. {
  30. return x == 0 && BitConverter.DoubleToInt64Bits(x) != NegativeZeroBits;
  31. }
  32. }
  33. }