Skip to content

Commit 05e976a

Browse files
committed
Update docs
1 parent a5c5196 commit 05e976a

4 files changed

Lines changed: 21 additions & 164 deletions

File tree

examples/chapter12_04a/chapter12_04a.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@
391391
<ItemGroup>
392392
<None Include="build.bat" />
393393
<None Include="build.sh" />
394+
<None Include="readme.md" />
394395
<None Include="src\util\STL\algorithm">
395396
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
396397
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>

examples/chapter12_04a/chapter12_04a.vcxproj.filters

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@
8282
<Filter Include="src\mcal\bl602_sifive_e24_riscv">
8383
<UniqueIdentifier>{fb640df6-2af7-454a-9b2a-828b481ce10f}</UniqueIdentifier>
8484
</Filter>
85+
<Filter Include="_doc">
86+
<UniqueIdentifier>{761f3b28-a64f-4507-93e8-aae698775a95}</UniqueIdentifier>
87+
</Filter>
8588
</ItemGroup>
8689
<ItemGroup>
8790
<ClCompile Include="src\mcal\mcal.cpp">
@@ -525,5 +528,8 @@
525528
</None>
526529
<None Include="build.bat" />
527530
<None Include="build.sh" />
531+
<None Include="readme.md">
532+
<Filter>_doc</Filter>
533+
</None>
528534
</ItemGroup>
529535
</Project>

examples/chapter12_04a/readme.md

Lines changed: 10 additions & 164 deletions
Original file line numberDiff line numberDiff line change
@@ -7,170 +7,16 @@ mathematics.
77

88
## Selected Special Functions
99

10-
Special functions such as the gamma function, Bessel functions,
11-
Legendre functions, zeta-type functions and many others
12-
are essential in pure and applied mathematics.
13-
Special functions are _special_ in the sense of generally
14-
being considered more specialized than elementary
15-
transecndental functions like trigonometric functions,
16-
logarithmic functions, exponential functions and the like.
10+
The same special functions and arguments are used as in
11+
Example Chapter12_04. In variation 12_04a, however,
12+
the open-source 32-bit BL602 single-core RISC-V (SiFive E24)
13+
microcontroller is used.
1714

18-
Many special functions, although they can be very difficult to calculate
19-
over wide parameter and argument ranges, have remarkably
20-
simple small-argument approximations such as a modest Taylor series.
15+
## Hardware Setup
2116

22-
Cylindrical Bessel functions of complex-valued argument $z$
23-
and complex-valued order $\nu$,
24-
for instance, have a Bessel function Taylor series representation:
17+
In this particular example, we have simply used a commercially-available
18+
BL602 single-core RISC-V (SiFive E24) board placed on a breadboard
19+
with soldered-on pins.
2520

26-
$$
27-
J_{\nu}(z)~=~\left(\frac{1}{2}z\right)^{\nu}\sum_{k=0}^{\infty}
28-
\frac{\left(-\frac{1}{4}z^{2}\right)^{k}}{{k!}\Gamma\left(\nu+k+1\right)}~{\text{.}}
29-
$$
30-
31-
## Application Description
32-
33-
The application benchmark task `app::benchmark::task_func()`
34-
calculates three individual floating-point special function
35-
values in small argument range. These include a cylindrical Bessel function,
36-
a generalized hypergeometric geometric function and a generalized
37-
Legendre function.
38-
39-
The Bessel function calculation, for instance, calculates the approximate numerical value
40-
of
41-
42-
$$J_{11/9}\left(\gamma\right)~{\approx}~0.1890533651853886085356717332711858771597{\ldots}$$
43-
44-
at fixed parameter points.
45-
See also [WolframAlpha](https://www.wolframalpha.com/input?i=N%5BBesselJ%5B11%2F9%2C+EulerGamma%5D%2C+40%5D)
46-
with the input `N[BesselJ[11/9, EulerGamma], 40]`.
47-
48-
Other fixed parameter points have been selected
49-
for the Legendre and hypergeometric functions as well, can be found
50-
in the original example code and is also shown in the snippet below.
51-
52-
```cpp
53-
void app::benchmark::task_func()
54-
{
55-
static std::uint_fast8_t app_benchmark_index;
56-
57-
app_benchmark_result_is_ok = true;
58-
59-
// Use a port pin to provide a real-time measurement.
60-
app_benchmark_port_type::set_pin_high();
61-
62-
if(app_benchmark_index == 0U)
63-
{
64-
// Test the value of a Bessel function.
65-
// Here is a control value from Wolfram Alpha.
66-
// N[BesselJ[11/9, EulerGamma], 40]
67-
// 0.1890533651853886085356717332711858771597
68-
69-
constexpr std::float32_t v = FLOAT32_C(11.0) / FLOAT32_C(9.0);
70-
71-
app_benchmark_result_bessel =
72-
math::functions::cyl_bessel_j(v, math::constants::euler<std::float32_t>());
73-
74-
app_benchmark_result_is_ok &= is_close_fraction(FLOAT32_C(0.1890533652),
75-
app_benchmark_result_bessel,
76-
app_benchmark_tolerance);
77-
}
78-
else if(app_benchmark_index == 1U)
79-
{
80-
// Test the value of a hypergeometric function.
81-
// Here is a control value from Wolfram Alpha.
82-
// N[HypergeometricPFQ[3/{7, 8, 9, 10}, 7/{13, 14, 15, 16, 17}, Log[2]], 40]
83-
// 1.583596313998374915091256357139915173598
84-
85-
constexpr std::array<std::float32_t, 4U> ap =
86-
{{
87-
FLOAT32_C(3.0) / FLOAT32_C( 7.0),
88-
FLOAT32_C(3.0) / FLOAT32_C( 8.0),
89-
FLOAT32_C(3.0) / FLOAT32_C( 9.0),
90-
FLOAT32_C(3.0) / FLOAT32_C(10.0)
91-
}};
92-
93-
constexpr std::array<std::float32_t, 5U> bq =
94-
{{
95-
FLOAT32_C(7.0) / FLOAT32_C(13.0),
96-
FLOAT32_C(7.0) / FLOAT32_C(14.0),
97-
FLOAT32_C(7.0) / FLOAT32_C(15.0),
98-
FLOAT32_C(7.0) / FLOAT32_C(16.0),
99-
FLOAT32_C(7.0) / FLOAT32_C(17.0)
100-
}};
101-
102-
app_benchmark_result_hypergeometric =
103-
math::functions::hypergeometric_pfq(ap.cbegin(),
104-
ap.cend(),
105-
bq.cbegin(),
106-
bq.cend(),
107-
math::constants::ln_two<std::float32_t>());
108-
109-
app_benchmark_result_is_ok &= is_close_fraction(FLOAT32_C(1.5835963140),
110-
app_benchmark_result_hypergeometric,
111-
app_benchmark_tolerance);
112-
}
113-
else if(app_benchmark_index == 2U)
114-
{
115-
// Test the value of a Legendre function of the first kind.
116-
// Here is a control value from Wolfram Alpha.
117-
// N[LegendreP[1/11, 14/19, 2/7], 40]
118-
// 0.2937838815278435137954432141091105343408
119-
constexpr std::float32_t v = FLOAT32_C( 1.0) / FLOAT32_C(11.0);
120-
constexpr std::float32_t u = FLOAT32_C(14.0) / FLOAT32_C(19.0);
121-
constexpr std::float32_t x = FLOAT32_C( 2.0) / FLOAT32_C( 7.0);
122-
123-
app_benchmark_result_legendre = math::functions::legendre_p(v, u, x);
124-
125-
app_benchmark_result_is_ok &= is_close_fraction(FLOAT32_C(0.2937838815),
126-
app_benchmark_result_legendre,
127-
app_benchmark_tolerance);
128-
}
129-
130-
app_benchmark_port_type::set_pin_low();
131-
132-
++app_benchmark_index;
133-
134-
if(app_benchmark_index == 3U)
135-
{
136-
app_benchmark_index = 0U;
137-
}
138-
139-
if(app_benchmark_result_is_ok == false)
140-
{
141-
// The result of this floating-point benchmark is not OK.
142-
143-
// Crash the system and toggle a port to provide an indication of failure.
144-
for(;;) { app_benchmark_port_type::toggle_pin(); mcal::cpu::nop(); }
145-
}
146-
}
147-
```
148-
149-
As usual, the benchmark port is toggled high prior to the
150-
floating-point calculation and low after the floating-point calculation.
151-
The three individual calculations are not calculated all at once
152-
in a single call of the benchmark task. Rather an index
153-
counting from zero to one to two selects one single special function
154-
calculation to be carried out per call cycle of the task.
155-
156-
The success of the calculation uses a relative
157-
measure of floating-point closeness based on the ratio of
158-
the expected answer with the control value compared with one.
159-
A simple template function called `is_close_fraction()`
160-
is used to test floating-point closeness as a ratio.
161-
162-
```cpp
163-
template<typename float_type>
164-
auto is_close_fraction(const float_type& left,
165-
const float_type& right,
166-
const float_type& tolerance) -> bool
167-
{
168-
const float_type ratio = left / right;
169-
170-
using std::fabs;
171-
172-
const float_type delta = fabs(static_cast<float_type>(FLOATMAX_C(1.0)) - fabs(ratio));
173-
174-
return (delta < tolerance);
175-
}
176-
```
21+
The wiring is straightforward. The blinking LED uses an external green LED
22+
controlled by pin `IO3`. THe benchmark toggle pin is `IO4`.

examples/readme.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ This example makes straightforward use of preemptive multitasking scheduling wit
104104
Example ![chapter12_04](https://github.com/ckormanyos/real-time-cpp/tree/master/examples/chapter12_04) Benchmarking Floating-Point Calculations.\
105105
This example performs a variety of floating-point calculations of selected special functions of pure and applied mathematics.
106106

107+
Example ![chapter12_04a](https://github.com/ckormanyos/real-time-cpp/tree/master/examples/chapter12_04a) Benchmarking Floating-Point Calculations (32-bit variation).\
108+
The same special functions and arguments are used as in Example Chapter12_04. In variation 12_04a, however,
109+
the open-source 32-bit BL602 single-core RISC-V (SiFive E24) microcontroller is used.
110+
107111
Example ![chapter16_08](https://github.com/ckormanyos/real-time-cpp/tree/master/examples/chapter16_08) Generating and displaying 128-bit Random Prime Numbers.\
108112
This advanced example uses an extended integer class to create 128-bit unsigned prime integers with primality testing performed via Miller-Rabin.
109113
This example also provides fascinating, intuitive, visual insight into the prime number theory of pure mathematics.

0 commit comments

Comments
 (0)