Efficient n-th Root Computation on Microcontrollers Employing Magic Constants and Modified Newton and Householder Methods
Abstract
1. Introduction
2. A Floating-Point Approximation of the n-th Root Functions with Magic Numbers
3. Multi-Interval Approximation
4. Modifications of the Newton–Raphson Method
4.1. Algorithms Based on Two Iterations
| Algorithm 1 rt_M1_n3 |
|
| Algorithm 2 rt_M1_n4 |
|
4.2. Algorithms Based on One Iteration
| Algorithm 3 rt_M1_n3_M16 |
|
| Algorithm 4 rt_M1_n4_M16 |
|
5. Modifications of the Householder Method
| Algorithm 5 rt_M2_n3_M2_H |
|
| Algorithm 6 rt_M2_n4_M2_H |
|
6. Approximation with a Single Magic Constant
| Algorithm 7 rt_3_M2M1 |
|
| Algorithm 8 rt_4_M2M1 |
|
7. Numerical Tests
- STM32F767ZIT6 (ARM Cortex-M7), operating at . The compiler used was arm-none-eabi-gcc with the following flags: -mcpu=cortex-m7 (target core), -mfpu=fpv4-sp-d16 (single-precision FPU), -mfloat-abi=hard (hardware floating-point instructions), -mthumb (Thumb instruction set), and -O3 (maximum speed optimization).
- STM32L432KCU6 (ARM Cortex-M4), operating at . The compiler used was arm-none-eabi-gcc with the following flags: -mcpu=cortex-m4, -mfpu=fpv4-sp-d16, -mfloat-abi=hard, -mthumb, and -O3.
- ESP32-D0WDQ6 (Xtensa LX6), operating at . The compiler used was xtensa-esp32-elf-gcc with the flag -O3.
- ESP32-S3 (Xtensa LX7), operating at . The compiler used was xtensa-esp32s3-elf-gcc with the flag -O3.
- ESP32-C3 (RISC-V RV32IMC), operating at . The compiler used was riscv32-esp-elf-gcc with the flag -O3.
8. Memory Usage Analysis
9. Conclusions
Author Contributions
Funding
Data Availability Statement
Conflicts of Interest
References
- Corey, R.M.; Singer, A.C. Modeling the Effects of Dynamic Range Compression on Signals in Noise. J. Acoust. Soc. Am. 2021, 150, 159–170. [Google Scholar] [CrossRef]
- Fattal, R.; Lischinski, D.; Werman, M. Gradient Domain High Dynamic Range Compression. In Seminal Graphics Papers: Pushing the Boundaries; Whitton, M.C., Ed.; ACM: New York, NY, USA, 2023; Volume 2, pp. 671–678. [Google Scholar]
- Severoglu, N.; Demir, Y.; Kaplan, N.H.; Kucuk, S. ACGC: Adaptive Chrominance Gamma Correction for Low-Light Image Enhancement. J. Vis. Commun. Image Represent. 2025, 107, 104402. [Google Scholar] [CrossRef]
- Nie, Z.; Long, T.; Zhou, Z. Research on Rotational Object Recognition Based on HSV Color Space and Gamma Correction. In Proceedings of the 6th International Symposium on Advanced Technologies and Applications in the Internet of Things, Kusatsu, Japan, 19–22 August 2024; pp. 19–22. [Google Scholar]
- Ngo, D.; Kang, B. Taylor-Series-Based Reconfigurability of Gamma Correction in Hardware Designs. Electronics 2021, 10, 1959. [Google Scholar]
- Oprzȩdkiewicz, K.; Rosół, M.; Żegleń-Włodarczyk, J. The Frequency and Real-Time Properties of the Microcontroller Implementation of Fractional-Order PID Controller. Electronics 2021, 10, 524. [Google Scholar] [CrossRef]
- Ferdi, Y. Some applications of fractional order calculus to design digital filters for biomedical signal processing. J. Mech. Med. Biol. 2012, 12, 1240008. [Google Scholar] [CrossRef]
- Zhu, J.Y.; Snowden, J.C.; Verdejo, J.; Chen, E.; Zhang, P.; Ghaednia, H.; Schwab, J.H.; Mueller, S. EIT-kit: An Electrical Impedance Tomography Toolkit for Health and Motion Sensing. In Proceedings of the 34th Annual ACM Symposium on User Interface Software and Technology (UIST ’21), Virtual Event, 10–14 October 2021; pp. 400–413. [Google Scholar]
- Telceken, M. A new feature extraction method for AI based classification of heart sounds: Dual-frequency cepstral coefficients (DFCCs). Eur. Phys. J. Spec. Top. 2025, 234, 4699–4710. [Google Scholar] [CrossRef]
- Fu, J.B.; Zhang, Y.; Liu, J.; Lian, X.C.; Tang, J.; Zhu, F. Pharmacometabonomics: Data processing and statistical analysis. Brief. Bioinform. 2021, 22, 1–25. [Google Scholar] [CrossRef]
- Echoukairi, H.; Ettaki, W.; Ghmary, M.E. Enhancing Call Detail Record Prediction with Machine Learning for Communication. In Connected Objects, Artificial Intelligence, Telecommunications and Electronics Engineering. COCIA 2025; Mejdoub, Y., Elamri, A., Kardouchi, M., Eds.; Lecture Notes in Networks and Systems; Springer: Cham, Switzerland, 2026; Volume 1584. [Google Scholar]
- Dike, A.O.; Chikezie, D.C.; Otuonye, E.L. Application of cube root transformation of error component of multiplicative time stress model. Eur. J. Stat. Probab. 2020, 8, 25–40. [Google Scholar]
- Murugesan, N.; Ramasamy, A.M.S. A numerical algorithm for nth root. J. Fundam. Sci. 2011, 7, 35–40. [Google Scholar] [CrossRef]
- Jo, J.; Park, I.-C. Low-Latency Low-Cost Architecture for Square and Cube Roots. IEICE Trans. Fundam. Electron. Commun. Comput. Sci. 2017, E100-A, 1951–1955. [Google Scholar]
- Aggarwal, S.; Garg1, N.; Kaur, G. Performance Evaluation of Various Dispersion Compensation Modules. Wirel. Pers. Commun. 2022, 123, 2011–2025. [Google Scholar] [CrossRef]
- Tukey, J.W. Exploratory Data Analysis; Addison-Wesley: Reading, MA, USA, 1977. [Google Scholar]
- Box, G.E.P.; Cox, D.R. An Analysis of Transformations. J. R. Stat. Soc. Ser. B 1964, 26, 211–243. [Google Scholar] [CrossRef]
- Zheng, H.; Cai, A.; Zhou, Q.; Xu, P.T.; Zhao, L.C.; Li, C.; Dong, B.J.; Gao, H.C. Optimal preprocessing of serum and urine metabolomic data fusion for staging prostate cancer through design of experiment. Anal. Chim. Acta 2017, 991, 68–75. [Google Scholar] [CrossRef] [PubMed]
- Li, A.; Zheng, C.; Peng, R.; Li, X. On the Importance of Power Compression and Phase Estimation in Monaural Speech Dereverberation. JASA Express Lett. 2021, 1, 014802. [Google Scholar] [CrossRef] [PubMed]
- Bendib, H.-E.; Bahri, M.; Boumehraz, M.; Mallem, A.; Hamzi, M. Implementation of a New Versatile Bio-Potential Measurement System. J. Circuits Syst. Comput. 2023, 32, 2350128. [Google Scholar] [CrossRef]
- Rakhmatulin, I. Low-Cost Shield MicroBCI to Measure EEG with STM32. arXiv 2025, arXiv:2509.16229. [Google Scholar]
- Santos, P.; Marquês, F.; Quintão, C.; Quaresma, C. Electromyographic and Kinematic Analysis of the Upper Limb During Drinking and Eating Using a Wearable Device Prototype. Sensors 2025, 25, 5227. [Google Scholar] [CrossRef]
- Altamimi, A.; Ben Youssef, B. Leveraging Seed Generation for Efficient Hardware Acceleration of Lossless Compression of Remotely Sensed Hyperspectral Images. Electronics 2024, 13, 2164. [Google Scholar] [CrossRef]
- Kusaka, T.; Tanaka, T. Pseudo-Normalization via Integer Fast Inverse Square Root and Its Application to Fast Computation without Division. Electronics 2024, 13, 2955. [Google Scholar] [CrossRef]
- Yu, B. Averaging-Based Method for Real-Time Estimation of Voltage Effective Value in Grid-Connected Inverters. Electronics 2025, 14, 3733. [Google Scholar] [CrossRef]
- Qin, L.; Wang, W.; Shi, M.; Liang, Y.; Tan, P. Attitude Calculation Method of Drilling Tools Based on Cross-Correlation Extraction and ASRUKF. Electronics 2024, 13, 1707. [Google Scholar] [CrossRef]
- Moroz, L.; Walczyk, C.J.; Hrynchyshyn, A.; Holimath, V.; Cieśliński, J.L. Fast calculation of inverse square root with the use of magic constant—Analytical approach. Appl. Math. Comput. 2018, 316, 245–255. [Google Scholar] [CrossRef]
- Walczyk, C.J.; Moroz, L.; Cieśliński, J.L. A modification of the fast inverse square root algorithm. Computation 2019, 7, 41. [Google Scholar] [CrossRef]
- Walczyk, C.J.; Moroz, L.; Cieśliński, J.L. Improving the accuracy of the fast inverse square root by modifying Newton-Raphson corrections. Entropy 2021, 23, 86. [Google Scholar] [CrossRef] [PubMed]
- Blinn, J. Floating-point tricks. IEEE Comput. Graph. Appl. Mag. 1997, 17, 80–84. [Google Scholar] [CrossRef]
- Moroz, L.; Samotyy, V.; Horyachyy, O.; Dzelendzyak, U. Algorithms for calculating the square root and inverse square root based on the second-order Householder’s method. In Proceedings of the 2019 10th IEEE International Conference on Intelligent Data Acquisition and Advanced Computing Systems: Technology and Applications (IDAACS), Metz, France, 18–21 September 2019; pp. 436–442. [Google Scholar]
- Moroz, L.; Samotyy, V. Efficient floating-point division for digital signal processing application. IEEE Signal Process. Mag. 2019, 36, 159–163. [Google Scholar] [CrossRef]
- Walczyk, C.J.; Moroz, L.V.; Samotyy, V.; Cieśliński, J.L. Optimal approximation of the 1/x function using Chebyshev polynomials and magic constants. ACM Trans. Math. Softw. 2025, 51, 2. [Google Scholar] [CrossRef]
- Walczyk, C.; Gepner, P.; Ltaief, H.; Gavkalova, N. On Floating Point Approximation of the Reciprocal Cube Root Function. In Computational Science—ICCS 2025 Workshops; Paszynski, M., Barnard, A.S., Zhang, Y.J., Eds.; Springer Nature: Cham, Switzerland, 2025; pp. 89–103. [Google Scholar]
- Moroz, L.; Samotyy, V.; Walczyk, C.J.; Cieśliński, J.L. Fast calculation of cube and inverse cube root using a magic constant and its implementation on microcontrollers. Energies 2021, 14, 1058. [Google Scholar] [CrossRef]
- Moroz, L.; Samotyy, V.; Walczyk, C. Fast Algorithms for Computing Floating-Point Reciprocal Cube Root Functions. Int. J. Comput. Sci. Netw. Secur. 2023, 23, 84–90. [Google Scholar] [CrossRef]
- Day, M. Generalising the Fast Reciprocal Square Root Algorithm. arXiv 2023, arXiv:2307.15600. [Google Scholar]
- IEEE Computer Society; Standards Committee; Working Group of the Microprocessor Standards Subcommittee; American National Standards Institute. IEEE Standard for Binary Floating-Point Arithmetic; IEEE: New York, NY, USA, 1985; Volume 754. [Google Scholar]



| 7 | 8 | 10 | 12 | 14 | |
| 7 | 8 | 10 | 12 | 14 | |
| 7 | 8 | 10 | 12 | 14 |
| 15 | 18 | 21 | 25 | 29 | |
| 31 | 38 | 44 | 52 | 60 |
| 15 | 18 | 21 | 25 | 29 | |
| 31 | 37 | 44 | 51 | 59 |
| 24 | 28 | 34 | 39 |
| 24 | 28 | 33 | 39 |
| 1 | 1 | 2 | 2 | |
| Method | Relative Errors | Execution Times | ||||||
|---|---|---|---|---|---|---|---|---|
| RMSEr | M7 | M4 | LX6 | LX7 | RISC-V | |||
| cbrtf | 101 | 93 | 222 | 229 | 1416 | |||
| rt_M1_n3 | 69 | 58 | 147 | 156 | 1616 | |||
| rt_M1_n3_M16 | 48 | 45 | 83 | 86 | 1058 | |||
| rt_M2_n3_M2_H | 55 | 47 | 93 | 94 | 1394 | |||
| rt_3_M2M1 | 69 | 54 | 144 | 154 | 1932 | |||
| Method | Relative Errors | Execution Times | ||||||
|---|---|---|---|---|---|---|---|---|
| RMSEr | M7 | M4 | LX6 | LX7 | RISC-V | |||
| 2×sqrtf | 42 | 37 | 152 | 137 | 1532 | |||
| rt_M1_n4 | 71 | 58 | 148 | 160 | 1862 | |||
| rt_M1_n4_M16 | 45 | 43 | 80 | 81 | 1173 | |||
| rt_M2_n4_M2_H | 49 | 41 | 84 | 86 | 1396 | |||
| rt_4_M2M1 | 70 | 55 | 146 | 154 | 2069 | |||
| Method | Program | Method | Program | ||
|---|---|---|---|---|---|
| rt_M1_n3 | 104B | 24B | rt_M1_n4 | 96B | 32B |
| rt_M1_n3_M16 | 80B | 384B | rt_M1_n4_M16 | 68B | 512B |
| rt_M2_n3_M2_H | 100B | 48B | rt_M2_n4_M2_H | 80B | 64B |
| rt_3_M2M1 | 112B | 0B | rt_4_M2M1 | 104B | 0B |
| Method | Program | Method | Program | ||
|---|---|---|---|---|---|
| rt_M1_n3 | 129B | 24B | rt_M1_n4 | 123B | 32B |
| rt_M1_n3_M16 | 91B | 384B | rt_M1_n4_M16 | 76B | 512B |
| rt_M2_n3_M2_H | 108B | 48B | rt_M2_n4_M2_H | 92B | 64B |
| rt_3_M2M1 | 119B | 0B | rt_4_M2M1 | 117B | 0B |
| Method | Program | Method | Program | ||
|---|---|---|---|---|---|
| rt_M1_n3 | 133B | 24B | rt_M1_n4 | 127B | 32B |
| rt_M1_n3_M16 | 91B | 384B | rt_M1_n4_M16 | 76B | 512B |
| rt_M2_n3_M2_H | 112B | 48B | rt_M2_n4_M2_H | 96B | 64B |
| rt_3_M2M1 | 127B | 0B | rt_4_M2M1 | 121B | 0B |
| Method | Program | Method | Program | ||
|---|---|---|---|---|---|
| rt_M1_n3 | 182B | 24B | rt_M1_n4 | 178B | 32B |
| rt_M1_n3_M16 | 124B | 384B | rt_M1_n4_M16 | 110B | 512B |
| rt_M2_n3_M2_H | 168B | 48B | rt_M2_n4_M2_H | 142B | 64B |
| rt_3_M2M1 | 192B | 0B | rt_4_M2M1 | 188B | 0B |
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content. |
© 2025 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license.
Share and Cite
Walczyk, C.J.; Jurgielewicz, M.; Cieśliński, J.L. Efficient n-th Root Computation on Microcontrollers Employing Magic Constants and Modified Newton and Householder Methods. Electronics 2026, 15, 129. https://doi.org/10.3390/electronics15010129
Walczyk CJ, Jurgielewicz M, Cieśliński JL. Efficient n-th Root Computation on Microcontrollers Employing Magic Constants and Modified Newton and Householder Methods. Electronics. 2026; 15(1):129. https://doi.org/10.3390/electronics15010129
Chicago/Turabian StyleWalczyk, Cezary J., Maciej Jurgielewicz, and Jan L. Cieśliński. 2026. "Efficient n-th Root Computation on Microcontrollers Employing Magic Constants and Modified Newton and Householder Methods" Electronics 15, no. 1: 129. https://doi.org/10.3390/electronics15010129
APA StyleWalczyk, C. J., Jurgielewicz, M., & Cieśliński, J. L. (2026). Efficient n-th Root Computation on Microcontrollers Employing Magic Constants and Modified Newton and Householder Methods. Electronics, 15(1), 129. https://doi.org/10.3390/electronics15010129

