Skip to content

Commit 3be56e6

Browse files
authored
Add 'constant' math ref page to core lib docs (#6630)
* add 'constant' ref page to core lib docs * toss in updated strings json * fix spelling of 'logarithm'
1 parent 43d6825 commit 3be56e6

File tree

3 files changed

+144
-4
lines changed

3 files changed

+144
-4
lines changed

docs/reference/math/constant.md

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
# Constant
2+
3+
A common mathematical constant value.
4+
5+
```sig
6+
Math._constant(Math.PI)
7+
```
8+
9+
There are several constant values that are important in calculations for science and engineering. The ``||math.constant||`` block provides several that you can use in your mathematical formulas and expressions.
10+
11+
## π
12+
13+
The value of Pi (π) which is the ratio of a circle's circumference to its diameter.
14+
15+
```block
16+
Math._constant(Math.PI)
17+
```
18+
19+
### Example
20+
21+
Get the area of a circle with a radius of `4`.
22+
23+
```block
24+
let circle_area = Math.PI * 4**2
25+
```
26+
27+
## e
28+
29+
Euler's number (e) which is the base of the natural logarithm and the exponential function.
30+
31+
```block
32+
Math._constant(Math.E)
33+
```
34+
35+
### Example
36+
37+
Find the half-life, in years, of radioactive decay for Carbon-14.
38+
39+
```block
40+
let time = 0
41+
let decay = 0.000121
42+
let carbon14 = 1
43+
while (carbon14 > 0.5) {
44+
carbon14 = Math.E ** (-1 * decay * time)
45+
time += 1
46+
}
47+
```
48+
49+
## ln(2)
50+
51+
Natural log of 2.
52+
53+
```block
54+
Math._constant(Math.LN2)
55+
```
56+
57+
### Example
58+
59+
Find out how many years will it take to double an investment using continuous compounding at 5% interest.
60+
61+
```block
62+
let years = Math.LN2 / 0.05
63+
```
64+
65+
## ln(10)
66+
67+
Natural log of 10.
68+
69+
```block
70+
Math._constant(Math.LN10)
71+
```
72+
73+
### Example
74+
75+
How many days will it take for bacteria in a culture to reach 10 times the start amount if they double in number each day.
76+
77+
```block
78+
let days = Math.LN10
79+
```
80+
81+
## log₂(e)
82+
83+
Convert from a natural logarithm to a base-2 logarithm.
84+
85+
```block
86+
Math._constant(Math.LOG2E)
87+
```
88+
89+
The log₂(e) constant is equal to ln(e) / ln(2) which is also 1 / ln(2).
90+
91+
## log₁₀(e)
92+
93+
Convert from a natural logarithm to a base-10 logarithm.
94+
95+
```block
96+
Math._constant(Math.LOG10E)
97+
```
98+
99+
The log₁₀(e) constant is equal to 1 / ln(10) which is also 1 / ln(10).
100+
101+
## √½
102+
103+
The square root of one half (1/2).
104+
105+
```block
106+
Math._constant(Math.SQRT1_2)
107+
```
108+
109+
### Example
110+
111+
Find the length of the sides of a square with a diagonal length of 9.
112+
113+
```block
114+
let side = 9 * Math.SQRT1_2
115+
```
116+
117+
## √2
118+
119+
The square root of 2.
120+
121+
```block
122+
Math._constant(Math.SQRT2)
123+
```
124+
125+
### Example
126+
127+
Find out how much shorter it is by walking across a square parking lot on a street corner than using the sidewalk on the sides. Each side of the parking lot is 50 meters.
128+
129+
```block
130+
let walk_diff = 2 * 50 - 50 * Math.SQRT2
131+
```

libs/core/_locales/core-jsdoc-strings.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"Array.reduce|param|callbackfn": "A function that accepts up to three arguments. The reduce method calls the callbackfn function one time for each element in the array.",
3939
"Array.reduce|param|initialValue": "Initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.",
4040
"Array.removeAt": "Remove and return the element at a certain index.",
41-
"Array.removeElement": "Remove the first occurence of an object. Returns true if removed.",
41+
"Array.removeElement": "Remove the first occurrence of an object. Returns true if removed.",
4242
"Array.reverse": "Reverse the elements in an array. The first array element becomes the last, and the last array element becomes the first.",
4343
"Array.set": "Store a value at a particular index",
4444
"Array.set|param|index": "the zero-based position in the list to store the value, eg: 0",
@@ -225,8 +225,8 @@
225225
"String.indexOf|param|start": "optional start index for the search",
226226
"String.isEmpty": "Returns a value indicating if the string is empty",
227227
"String.length": "Returns the length of a String object.",
228-
"String.replace": "Return the current string with the first occurence of toReplace\nreplaced with the replacer\n\n\nor a function that accepts the substring and returns the replacement string.",
229-
"String.replaceAll": "Return the current string with each occurence of toReplace\nreplaced with the replacer\n\n\nor a function that accepts the substring and returns the replacement string.",
228+
"String.replace": "Return the current string with the first occurrence of toReplace\nreplaced with the replacer\n\n\nor a function that accepts the substring and returns the replacement string.",
229+
"String.replaceAll": "Return the current string with each occurrence of toReplace\nreplaced with the replacer\n\n\nor a function that accepts the substring and returns the replacement string.",
230230
"String.replaceAll|param|replacer": "either the string that replaces toReplace in the current string,",
231231
"String.replaceAll|param|toReplace": "the substring to replace in the current string",
232232
"String.replace|param|replacer": "either the string that replaces toReplace in the current string,",
@@ -707,7 +707,7 @@
707707
"serial.delimiters": "Return the corresponding delimiter string",
708708
"serial.onDataReceived": "Register an event to be fired when one of the delimiter is matched.",
709709
"serial.onDataReceived|param|delimiters": "the characters to match received characters against.",
710-
"serial.readBuffer": "Read multiple characters from the receive buffer. \nIf length is positive, pauses until enough characters are present.",
710+
"serial.readBuffer": "Read multiple characters from the receive buffer.\nIf length is positive, pauses until enough characters are present.",
711711
"serial.readBuffer|param|length": "default buffer length",
712712
"serial.readLine": "Read a line of text from the serial port.",
713713
"serial.readString": "Read the buffered received data as a string",

libs/core/_locales/core-strings.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,15 @@
145145
"LedSpriteProperty.Direction|block": "direction",
146146
"LedSpriteProperty.X|block": "x",
147147
"LedSpriteProperty.Y|block": "y",
148+
"Math.E|block": "e",
149+
"Math.LN10|block": "ln(10)",
150+
"Math.LN2|block": "ln(2)",
151+
"Math.LOG10E|block": "log₁₀(e)",
152+
"Math.LOG2E|block": "log₂(e)",
153+
"Math.PI|block": "π",
154+
"Math.SQRT1_2|block": "√½",
155+
"Math.SQRT2|block": "√2",
156+
"Math._constant|block": "$MEMBER",
148157
"Math.constrain|block": "constrain %value|between %low|and %high",
149158
"Math.map|block": "map %value|from low %fromLow|high %fromHigh|to low %toLow|high %toHigh",
150159
"Math.randomBoolean|block": "pick random true or false",

0 commit comments

Comments
 (0)