FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
mathjs/src/constants.js at develop · intervalia/mathjs · GitHub
intervalia
/
mathjs
Public
forked from
josdejong/mathjs
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
mathjs
/
src
/
constants.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
81 lines (68 loc) · 3.32 KB
Breadcrumbs
mathjs
/
src
/
constants.js
Copy path
File metadata and controls
81 lines (68 loc) · 3.32 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
'use strict'
const
object
=
require
(
'./utils/object'
)
const
bigConstants
=
require
(
'./utils/bignumber/constants'
)
function
factory
(
type
,
config
,
load
,
typed
,
math
)
{
// listen for changed in the configuration, automatically reload
// constants when needed
math
.
on
(
'config'
,
function
(
curr
,
prev
)
{
if
(
curr
.
number
!==
prev
.
number
)
{
factory
(
type
,
config
,
load
,
typed
,
math
)
}
}
)
setConstant
(
math
,
'true'
,
true
)
setConstant
(
math
,
'false'
,
false
)
setConstant
(
math
,
'null'
,
null
)
setConstant
(
math
,
'uninitialized'
,
'Error: Constant uninitialized is removed since v4.0.0. Use null instead'
)
if
(
config
.
number
===
'BigNumber'
)
{
setConstant
(
math
,
'Infinity'
,
new
type
.
BigNumber
(
Infinity
)
)
setConstant
(
math
,
'NaN'
,
new
type
.
BigNumber
(
NaN
)
)
setLazyConstant
(
math
,
'pi'
,
function
(
)
{
return
bigConstants
.
pi
(
type
.
BigNumber
)
}
)
setLazyConstant
(
math
,
'tau'
,
function
(
)
{
return
bigConstants
.
tau
(
type
.
BigNumber
)
}
)
setLazyConstant
(
math
,
'e'
,
function
(
)
{
return
bigConstants
.
e
(
type
.
BigNumber
)
}
)
setLazyConstant
(
math
,
'phi'
,
function
(
)
{
return
bigConstants
.
phi
(
type
.
BigNumber
)
}
)
// golden ratio, (1+sqrt(5))/2
// uppercase constants (for compatibility with built-in Math)
setLazyConstant
(
math
,
'E'
,
function
(
)
{
return
math
.
e
}
)
setLazyConstant
(
math
,
'LN2'
,
function
(
)
{
return
new
type
.
BigNumber
(
2
)
.
ln
(
)
}
)
setLazyConstant
(
math
,
'LN10'
,
function
(
)
{
return
new
type
.
BigNumber
(
10
)
.
ln
(
)
}
)
setLazyConstant
(
math
,
'LOG2E'
,
function
(
)
{
return
new
type
.
BigNumber
(
1
)
.
div
(
new
type
.
BigNumber
(
2
)
.
ln
(
)
)
}
)
setLazyConstant
(
math
,
'LOG10E'
,
function
(
)
{
return
new
type
.
BigNumber
(
1
)
.
div
(
new
type
.
BigNumber
(
10
)
.
ln
(
)
)
}
)
setLazyConstant
(
math
,
'PI'
,
function
(
)
{
return
math
.
pi
}
)
setLazyConstant
(
math
,
'SQRT1_2'
,
function
(
)
{
return
new
type
.
BigNumber
(
'0.5'
)
.
sqrt
(
)
}
)
setLazyConstant
(
math
,
'SQRT2'
,
function
(
)
{
return
new
type
.
BigNumber
(
2
)
.
sqrt
(
)
}
)
}
else
{
setConstant
(
math
,
'Infinity'
,
Infinity
)
setConstant
(
math
,
'NaN'
,
NaN
)
setConstant
(
math
,
'pi'
,
Math
.
PI
)
setConstant
(
math
,
'tau'
,
Math
.
PI
*
2
)
setConstant
(
math
,
'e'
,
Math
.
E
)
setConstant
(
math
,
'phi'
,
1.61803398874989484820458683436563811772030917980576286213545
)
// golden ratio, (1+sqrt(5))/2
// uppercase constants (for compatibility with built-in Math)
setConstant
(
math
,
'E'
,
math
.
e
)
setConstant
(
math
,
'LN2'
,
Math
.
LN2
)
setConstant
(
math
,
'LN10'
,
Math
.
LN10
)
setConstant
(
math
,
'LOG2E'
,
Math
.
LOG2E
)
setConstant
(
math
,
'LOG10E'
,
Math
.
LOG10E
)
setConstant
(
math
,
'PI'
,
math
.
pi
)
setConstant
(
math
,
'SQRT1_2'
,
Math
.
SQRT1_2
)
setConstant
(
math
,
'SQRT2'
,
Math
.
SQRT2
)
}
// complex i
if
(
type
.
Complex
)
{
setConstant
(
math
,
'i'
,
type
.
Complex
.
I
)
}
// meta information
setConstant
(
math
,
'version'
,
require
(
'./version'
)
)
}
// create a constant in both math and mathWithTransform
function
setConstant
(
math
,
name
,
value
)
{
math
[
name
]
=
value
math
.
expression
.
mathWithTransform
[
name
]
=
value
}
// create a lazy constant in both math and mathWithTransform
function
setLazyConstant
(
math
,
name
,
resolver
)
{
object
.
lazy
(
math
,
name
,
resolver
)
object
.
lazy
(
math
.
expression
.
mathWithTransform
,
name
,
resolver
)
}
exports
.
factory
=
factory
exports
.
lazy
=
false
// no lazy loading of constants, the constants themselves are lazy when needed
exports
.
math
=
true
// request access to the math namespace
Back
|
FazBrowse Home
|
New Git URL