NumberInstance.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System;
  2. using Jint.Native.Object;
  3. using Jint.Runtime;
  4. namespace Jint.Native.Number
  5. {
  6. public class NumberInstance : ObjectInstance, IPrimitiveInstance
  7. {
  8. private static readonly long NegativeZeroBits = BitConverter.DoubleToInt64Bits(-0.0);
  9. public NumberInstance(Engine engine)
  10. : base(engine)
  11. {
  12. }
  13. public override string Class
  14. {
  15. get
  16. {
  17. return "Number";
  18. }
  19. }
  20. Types IPrimitiveInstance.Type
  21. {
  22. get { return Types.Number; }
  23. }
  24. JsValue IPrimitiveInstance.PrimitiveValue
  25. {
  26. get { return PrimitiveValue; }
  27. }
  28. public JsValue PrimitiveValue { get; set; }
  29. public static bool IsNegativeZero(double x)
  30. {
  31. return x == 0 && BitConverter.DoubleToInt64Bits(x) == NegativeZeroBits;
  32. }
  33. public static bool IsPositiveZero(double x)
  34. {
  35. return x == 0 && BitConverter.DoubleToInt64Bits(x) != NegativeZeroBits;
  36. }
  37. }
  38. }