pxt-common-packages 12.3.31 → 13.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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 logrithm 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 logrithm to a base-2 logrithm.
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 logrithm to a base-10 logrithm.
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
+ ```
package/libs/base/math.ts CHANGED
@@ -96,6 +96,7 @@ namespace Math {
96
96
  //% block="$MEMBER"
97
97
  //% constantShim
98
98
  //% weight=0
99
+ //% help=math/constant
99
100
  export function _constant(MEMBER: number): number {
100
101
  return MEMBER;
101
102
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pxt-common-packages",
3
- "version": "12.3.31",
3
+ "version": "13.0.0",
4
4
  "description": "Microsoft MakeCode (PXT) common packages",
5
5
  "keywords": [
6
6
  "MakeCode",