Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. JavaScript Numbers are represented as [IEEE 754 double-precision floats](http://steve.hollasch.net/cgindex/coding/ieeefloat.html). Unfortunately, this means they lose integer precision for values beyond +/- 2^^53. For projects that need to accurately handle 64-bit ints, such as [node-thrift](https://github.com/wadey/node-thrift), a performant, Number-like class is needed. Int64 is that class.
  2. Int64 instances look and feel much like JS-native Numbers. By way of example ...
  3. ```js
  4. // First, let's illustrate the problem ...
  5. > (0x123456789).toString(16)
  6. '123456789' // <- what we expect.
  7. > (0x123456789abcdef0).toString(16)
  8. '123456789abcdf00' // <- Ugh! JS doesn't do big ints. :(
  9. // So let's create a couple Int64s using the above values ...
  10. // Require, of course
  11. > Int64 = require('node-int64')
  12. // x's value is what we expect (the decimal value of 0x123456789)
  13. > x = new Int64(0x123456789)
  14. [Int64 value:4886718345 octets:00 00 00 01 23 45 67 89]
  15. // y's value is Infinity because it's outside the range of integer
  16. // precision. But that's okay - it's still useful because it's internal
  17. // representation (octets) is what we passed in
  18. > y = new Int64('123456789abcdef0')
  19. [Int64 value:Infinity octets:12 34 56 78 9a bc de f0]
  20. // Let's do some math. Int64's behave like Numbers. (Sorry, Int64 isn't
  21. // for doing 64-bit integer arithmetic (yet) - it's just for carrying
  22. // around int64 values
  23. > x + 1
  24. 4886718346
  25. > y + 1
  26. Infinity
  27. // Int64 string operations ...
  28. > 'value: ' + x
  29. 'value: 4886718345'
  30. > 'value: ' + y
  31. 'value: Infinity'
  32. > x.toString(2)
  33. '100100011010001010110011110001001'
  34. > y.toString(2)
  35. 'Infinity'
  36. // Use JS's isFinite() method to see if the Int64 value is in the
  37. // integer-precise range of JS values
  38. > isFinite(x)
  39. true
  40. > isFinite(y)
  41. false
  42. // Get an octet string representation. (Yay, y is what we put in!)
  43. > x.toOctetString()
  44. '0000000123456789'
  45. > y.toOctetString()
  46. '123456789abcdef0'
  47. // Finally, some other ways to create Int64s ...
  48. // Pass hi/lo words
  49. > new Int64(0x12345678, 0x9abcdef0)
  50. [Int64 value:Infinity octets:12 34 56 78 9a bc de f0]
  51. // Pass a Buffer
  52. > new Int64(new Buffer([0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0]))
  53. [Int64 value:Infinity octets:12 34 56 78 9a bc de f0]
  54. // Pass a Buffer and offset
  55. > new Int64(new Buffer([0,0,0,0,0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0]), 4)
  56. [Int64 value:Infinity octets:12 34 56 78 9a bc de f0]
  57. // Pull out into a buffer
  58. > new Int64(new Buffer([0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0])).toBuffer()
  59. <Buffer 12 34 56 78 9a bc de f0>
  60. // Or copy into an existing one (at an offset)
  61. > var buf = new Buffer(1024);
  62. > new Int64(new Buffer([0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0])).copy(buf, 512);
  63. ```