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 8.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. ![decimal.js](https://raw.githubusercontent.com/MikeMcl/decimal.js/gh-pages/decimaljs.png)
  2. An arbitrary-precision Decimal type for JavaScript.
  3. [![npm version](https://img.shields.io/npm/v/decimal.js.svg)](https://www.npmjs.com/package/decimal.js)
  4. [![npm downloads](https://img.shields.io/npm/dw/decimal.js)](https://www.npmjs.com/package/decimal.js)
  5. [![Build Status](https://travis-ci.org/MikeMcl/decimal.js.svg)](https://travis-ci.org/MikeMcl/decimal.js)
  6. [![CDNJS](https://img.shields.io/cdnjs/v/decimal.js.svg)](https://cdnjs.com/libraries/decimal.js)
  7. <br>
  8. ## Features
  9. - Integers and floats
  10. - Simple but full-featured API
  11. - Replicates many of the methods of JavaScript's `Number.prototype` and `Math` objects
  12. - Also handles hexadecimal, binary and octal values
  13. - Faster, smaller, and perhaps easier to use than JavaScript versions of Java's BigDecimal
  14. - No dependencies
  15. - Wide platform compatibility: uses JavaScript 1.5 (ECMAScript 3) features only
  16. - Comprehensive [documentation](https://mikemcl.github.io/decimal.js/) and test set
  17. - Used under the hood by [math.js](https://github.com/josdejong/mathjs)
  18. - Includes a TypeScript declaration file: *decimal.d.ts*
  19. ![API](https://raw.githubusercontent.com/MikeMcl/decimal.js/gh-pages/API.png)
  20. The library is similar to [bignumber.js](https://github.com/MikeMcl/bignumber.js/), but here
  21. precision is specified in terms of significant digits rather than decimal places, and all
  22. calculations are rounded to the precision (similar to Python's decimal module) rather than just
  23. those involving division.
  24. This library also adds the trigonometric functions, among others, and supports non-integer powers,
  25. which makes it a significantly larger library than *bignumber.js* and the even smaller
  26. [big.js](https://github.com/MikeMcl/big.js/).
  27. For a lighter version of this library without the trigonometric functions see
  28. [decimal.js-light](https://github.com/MikeMcl/decimal.js-light/).
  29. ## Load
  30. The library is the single JavaScript file *decimal.js* or ES module *decimal.mjs*.
  31. Browser:
  32. ```html
  33. <script src='path/to/decimal.js'></script>
  34. <script type="module">
  35. import Decimal from './path/to/decimal.mjs';
  36. ...
  37. </script>
  38. ```
  39. [Node.js](https://nodejs.org):
  40. ```bash
  41. npm install decimal.js
  42. ```
  43. ```js
  44. const Decimal = require('decimal.js');
  45. import Decimal from 'decimal.js';
  46. import {Decimal} from 'decimal.js';
  47. ```
  48. ## Use
  49. *In all examples below, semicolons and `toString` calls are not shown.
  50. If a commented-out value is in quotes it means `toString` has been called on the preceding expression.*
  51. The library exports a single constructor function, `Decimal`, which expects a single argument that is a number, string or Decimal instance.
  52. ```js
  53. x = new Decimal(123.4567)
  54. y = new Decimal('123456.7e-3')
  55. z = new Decimal(x)
  56. x.equals(y) && y.equals(z) && x.equals(z) // true
  57. ```
  58. If using values with more than a few digits, it is recommended to pass strings rather than numbers to avoid a potential loss of precision.
  59. ```js
  60. // Precision loss from using numeric literals with more than 15 significant digits.
  61. new Decimal(1.0000000000000001) // '1'
  62. new Decimal(88259496234518.57) // '88259496234518.56'
  63. new Decimal(99999999999999999999) // '100000000000000000000'
  64. // Precision loss from using numeric literals outside the range of Number values.
  65. new Decimal(2e+308) // 'Infinity'
  66. new Decimal(1e-324) // '0'
  67. // Precision loss from the unexpected result of arithmetic with Number values.
  68. new Decimal(0.7 + 0.1) // '0.7999999999999999'
  69. ```
  70. As with JavaScript numbers, strings can contain underscores as separators to improve readability.
  71. ```js
  72. x = new Decimal('2_147_483_647')
  73. ```
  74. String values in binary, hexadecimal or octal notation are also accepted if the appropriate prefix is included.
  75. ```js
  76. x = new Decimal('0xff.f') // '255.9375'
  77. y = new Decimal('0b10101100') // '172'
  78. z = x.plus(y) // '427.9375'
  79. z.toBinary() // '0b110101011.1111'
  80. z.toBinary(13) // '0b1.101010111111p+8'
  81. // Using binary exponential notation to create a Decimal with the value of `Number.MAX_VALUE`.
  82. x = new Decimal('0b1.1111111111111111111111111111111111111111111111111111p+1023')
  83. // '1.7976931348623157081e+308'
  84. ```
  85. Decimal instances are immutable in the sense that they are not changed by their methods.
  86. ```js
  87. 0.3 - 0.1 // 0.19999999999999998
  88. x = new Decimal(0.3)
  89. x.minus(0.1) // '0.2'
  90. x // '0.3'
  91. ```
  92. The methods that return a Decimal can be chained.
  93. ```js
  94. x.dividedBy(y).plus(z).times(9).floor()
  95. x.times('1.23456780123456789e+9').plus(9876.5432321).dividedBy('4444562598.111772').ceil()
  96. ```
  97. Many method names have a shorter alias.
  98. ```js
  99. x.squareRoot().dividedBy(y).toPower(3).equals(x.sqrt().div(y).pow(3)) // true
  100. x.comparedTo(y.modulo(z).negated() === x.cmp(y.mod(z).neg()) // true
  101. ```
  102. Most of the methods of JavaScript's `Number.prototype` and `Math` objects are replicated.
  103. ```js
  104. x = new Decimal(255.5)
  105. x.toExponential(5) // '2.55500e+2'
  106. x.toFixed(5) // '255.50000'
  107. x.toPrecision(5) // '255.50'
  108. Decimal.sqrt('6.98372465832e+9823') // '8.3568682281821340204e+4911'
  109. Decimal.pow(2, 0.0979843) // '1.0702770511687781839'
  110. // Using `toFixed()` to avoid exponential notation:
  111. x = new Decimal('0.0000001')
  112. x.toString() // '1e-7'
  113. x.toFixed() // '0.0000001'
  114. ```
  115. And there are `isNaN` and `isFinite` methods, as `NaN` and `Infinity` are valid `Decimal` values.
  116. ```js
  117. x = new Decimal(NaN) // 'NaN'
  118. y = new Decimal(Infinity) // 'Infinity'
  119. x.isNaN() && !y.isNaN() && !x.isFinite() && !y.isFinite() // true
  120. ```
  121. There is also a `toFraction` method with an optional *maximum denominator* argument.
  122. ```js
  123. z = new Decimal(355)
  124. pi = z.dividedBy(113) // '3.1415929204'
  125. pi.toFraction() // [ '7853982301', '2500000000' ]
  126. pi.toFraction(1000) // [ '355', '113' ]
  127. ```
  128. All calculations are rounded according to the number of significant digits and rounding mode specified
  129. by the `precision` and `rounding` properties of the Decimal constructor.
  130. For advanced usage, multiple Decimal constructors can be created, each with their own independent
  131. configuration which applies to all Decimal numbers created from it.
  132. ```js
  133. // Set the precision and rounding of the default Decimal constructor
  134. Decimal.set({ precision: 5, rounding: 4 })
  135. // Create another Decimal constructor, optionally passing in a configuration object
  136. Dec = Decimal.clone({ precision: 9, rounding: 1 })
  137. x = new Decimal(5)
  138. y = new Dec(5)
  139. x.div(3) // '1.6667'
  140. y.div(3) // '1.66666666'
  141. ```
  142. The value of a Decimal is stored in a floating point format in terms of its digits, exponent and sign, but these properties should be considered read-only.
  143. ```js
  144. x = new Decimal(-12345.67);
  145. x.d // [ 12345, 6700000 ] digits (base 10000000)
  146. x.e // 4 exponent (base 10)
  147. x.s // -1 sign
  148. ```
  149. For further information see the [API](http://mikemcl.github.io/decimal.js/) reference in the *doc* directory.
  150. ## Test
  151. To run the tests using Node.js from the root directory:
  152. ```bash
  153. npm test
  154. ```
  155. Each separate test module can also be executed individually, for example:
  156. ```bash
  157. node test/modules/toFraction
  158. ```
  159. To run the tests in a browser, open *test/test.html*.
  160. ## Minify
  161. Two minification examples:
  162. Using [uglify-js](https://github.com/mishoo/UglifyJS) to minify the *decimal.js* file:
  163. ```bash
  164. npm install uglify-js -g
  165. uglifyjs decimal.js --source-map url=decimal.min.js.map -c -m -o decimal.min.js
  166. ```
  167. Using [terser](https://github.com/terser/terser) to minify the ES module version, *decimal.mjs*:
  168. ```bash
  169. npm install terser -g
  170. terser decimal.mjs --source-map url=decimal.min.mjs.map -c -m --toplevel -o decimal.min.mjs
  171. ```
  172. ```js
  173. import Decimal from './decimal.min.mjs';
  174. ```
  175. ## Licence
  176. [The MIT Licence (Expat).](LICENCE.md)