Skip to content

Commit dce6aa0

Browse files
committed
Missing Number properties
No pun intended, a number of properties are missing from JavaScript’s `Number` as seen here: https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-number.epsilon This includes: `EPSILON`, `NEGATIVE_INFINITY`, `MAX_VALUE`, and `MIN_VALUE`. I have a current use case for `MAX_VALUE`.
1 parent f5bbd96 commit dce6aa0

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Notable changes to this project are documented in this file. The format is based
77
Breaking changes:
88

99
New features:
10+
- Added `epsilon`, `negativeInfinity`, `maxValue`, and `minValue` from JavaScript’s `Number` properties (#19 by @toastal)
1011

1112
Bugfixes:
1213

src/Data/Number.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
/* globals exports */
22
"use strict";
33

4+
exports.epsilon = Number.EPSILON;
5+
46
exports.nan = NaN;
57

68
exports.isNaN = isNaN;
79

810
exports.infinity = Infinity;
911

12+
exports.negativeInfinity = Number.NEGATIVE_INFINITY;
13+
1014
exports.isFinite = isFinite;
1115

1216
exports.fromStringImpl = function(str, isFinite, just, nothing) {
@@ -17,3 +21,7 @@ exports.fromStringImpl = function(str, isFinite, just, nothing) {
1721
return nothing;
1822
}
1923
};
24+
25+
exports.maxValue = Number.MAX_VALUE;
26+
27+
exports.minValue = Number.MIN_VALUE;

src/Data/Number.purs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,37 @@
11
-- | Functions for working with PureScripts builtin `Number` type.
22
module Data.Number
33
( fromString
4+
, epsilon
45
, nan
56
, isNaN
67
, infinity
8+
, negativeInfinity
79
, isFinite
10+
, minValue
11+
, maxValue
812
) where
913

1014
import Data.Function.Uncurried (Fn4, runFn4)
1115
import Data.Maybe (Maybe(..))
1216

17+
-- | The `Number` value for the magnitude of the difference between 1 and
18+
-- | the smallest value greater than 1 that is representable as a
19+
-- | `Number` value, which is approximately
20+
-- | 2.2204460492503130808472633361816 × 10⁻¹⁶
21+
foreign import epsilon :: Number
22+
1323
-- | Not a number (NaN)
1424
foreign import nan :: Number
1525

1626
-- | Test whether a number is NaN
1727
foreign import isNaN :: Number -> Boolean
1828

19-
-- | Positive infinity
29+
-- | Positive infinity, +∞𝔽
2030
foreign import infinity :: Number
2131

32+
-- | Negative inifinity, -∞𝔽
33+
foreign import negativeInfinity :: Number
34+
2235
-- | Test whether a number is finite
2336
foreign import isFinite :: Number -> Boolean
2437

@@ -53,3 +66,11 @@ fromString :: String -> Maybe Number
5366
fromString str = runFn4 fromStringImpl str isFinite Just Nothing
5467

5568
foreign import fromStringImpl :: Fn4 String (Number -> Boolean) (forall a. a -> Maybe a) (forall a. Maybe a) (Maybe Number)
69+
70+
-- | The largest positive finite value of the `Number` type, which is
71+
-- | approximately 1.7976931348623157 × 10³⁰⁸
72+
foreign import maxValue :: Number
73+
74+
-- | The smallest positive value of the `Number` type, which is
75+
-- | approximately 5 × 10⁻³²⁴
76+
foreign import minValue :: Number

0 commit comments

Comments
 (0)