Modified Fast Inverse Square Root and Square Root Approximation Algorithms: The Method of Switching Magic Constants

Many low-cost platforms that support floating-point arithmetic, such as microcontrollers and field-programmable gate arrays, do not include fast hardware or software methods for calculating the square root and/or reciprocal square root. Typically, such functions are implemented using direct lookup t...

Full description

Saved in:
Bibliographic Details
Published in:Computation Vol. 9; no. 2; p. 21
Main Authors: Moroz, Leonid V., Samotyy, Volodymyr V., Horyachyy, Oleh Y.
Format: Journal Article
Language:English
Published: MDPI AG 01.02.2021
Subjects:
ISSN:2079-3197, 2079-3197
Online Access:Get full text
Tags: Add Tag
No Tags, Be the first to tag this record!
Abstract Many low-cost platforms that support floating-point arithmetic, such as microcontrollers and field-programmable gate arrays, do not include fast hardware or software methods for calculating the square root and/or reciprocal square root. Typically, such functions are implemented using direct lookup tables or polynomial approximations, with a subsequent application of the Newton–Raphson method. Other, more complex solutions include high-radix digit-recurrence and bipartite or multipartite table-based methods. In contrast, this article proposes a simple modification of the fast inverse square root method that has high accuracy and relatively low latency. Algorithms are given in C/C++ for single- and double-precision numbers in the IEEE 754 format for both square root and reciprocal square root functions. These are based on the switching of magic constants in the initial approximation, depending on the input interval of the normalized floating-point numbers, in order to minimize the maximum relative error on each subinterval after the first iteration—giving 13 correct bits of the result. Our experimental results show that the proposed algorithms provide a fairly good trade-off between accuracy and latency after two iterations for numbers of type float, and after three iterations for numbers of type double when using fused multiply–add instructions—giving almost complete accuracy.
AbstractList Many low-cost platforms that support floating-point arithmetic, such as microcontrollers and field-programmable gate arrays, do not include fast hardware or software methods for calculating the square root and/or reciprocal square root. Typically, such functions are implemented using direct lookup tables or polynomial approximations, with a subsequent application of the Newton–Raphson method. Other, more complex solutions include high-radix digit-recurrence and bipartite or multipartite table-based methods. In contrast, this article proposes a simple modification of the fast inverse square root method that has high accuracy and relatively low latency. Algorithms are given in C/C++ for single- and double-precision numbers in the IEEE 754 format for both square root and reciprocal square root functions. These are based on the switching of magic constants in the initial approximation, depending on the input interval of the normalized floating-point numbers, in order to minimize the maximum relative error on each subinterval after the first iteration—giving 13 correct bits of the result. Our experimental results show that the proposed algorithms provide a fairly good trade-off between accuracy and latency after two iterations for numbers of type float, and after three iterations for numbers of type double when using fused multiply–add instructions—giving almost complete accuracy.
Author Moroz, Leonid V.
Samotyy, Volodymyr V.
Horyachyy, Oleh Y.
Author_xml – sequence: 1
  givenname: Leonid V.
  surname: Moroz
  fullname: Moroz, Leonid V.
– sequence: 2
  givenname: Volodymyr V.
  orcidid: 0000-0003-2344-2576
  surname: Samotyy
  fullname: Samotyy, Volodymyr V.
– sequence: 3
  givenname: Oleh Y.
  orcidid: 0000-0003-4948-458X
  surname: Horyachyy
  fullname: Horyachyy, Oleh Y.
BookMark eNp9kdtKAzEQhoMoWKsv4FVeoJrDbrPrXSkeCi2C1utlkkzaSLupSerh7a2tiAdwbubA_N8M_Edkvw0tEnLK2ZmUNTs3YblaZ8g-tDUTjAm-RzqCqbonea32v9WH5CSlR7aJmstKsA5Jk2C982jpFaRMR-0zxoT0_mkNEeldCJlCa3_0g9Uqhle_3B6kg8UsRJ_ny3RBp3OkE8zzYGlw9P7FZzP37YxOYOYNHYY2ZWhzOiYHDhYJTz5zlzxcXU6HN73x7fVoOBj3jCxV7lllZeUQS6UQtFJamb4TzAGiFsqWTBmNvEBV8n6_UAJdn2ldVsicMwZAdslox7UBHptV3Lwc35oAvtkOQpw1ELM3C2xQSHDG8dpaXZSu0lyWUuuikBLqGtiGJXYsE0NKEd0Xj7Pmw4XmrwsbUfVLZPxuI0fwi_-k78ZClmI
CitedBy_id crossref_primary_10_3390_electronics11152285
crossref_primary_10_1007_s11075_024_01932_7
crossref_primary_10_1038_s41598_022_25039_y
crossref_primary_10_1109_ACCESS_2021_3072495
crossref_primary_10_3390_electronics13152955
crossref_primary_10_3390_s22207989
crossref_primary_10_1109_MSP_2022_3157460
Cites_doi 10.1007/978-3-319-76526-6
10.1109/ISCE.2015.7177775
10.1109/ICAEE.2014.6838433
10.3390/e23010086
10.1109/ICPP.2017.52
10.47839/ijc.18.4.1616
10.1016/j.amc.2017.08.025
10.1109/VLSID.2017.60
10.1109/TC.2005.54
10.1109/TBCAS.2014.2376956
10.1109/MSP.2005.1406500
10.1109/DEVIC.2017.8073975
10.1023/A:1009984523264
10.1109/IDAACS.2019.8924302
10.1109/TC.2019.2947899
10.1201/b17296
10.1109/12.795125
10.1109/JPROC.2020.2991885
10.1109/IDAACS-SWS.2018.8525803
10.1016/j.sysarc.2017.06.005
ContentType Journal Article
DBID AAYXX
CITATION
DOA
DOI 10.3390/computation9020021
DatabaseName CrossRef
DOAJ Open Access Full Text
DatabaseTitle CrossRef
DatabaseTitleList CrossRef

Database_xml – sequence: 1
  dbid: DOA
  name: DOAJ Directory of Open Access Journals
  url: https://www.doaj.org/
  sourceTypes: Open Website
DeliveryMethod fulltext_linktorsrc
Discipline Sciences (General)
Mathematics
EISSN 2079-3197
ExternalDocumentID oai_doaj_org_article_e23afcf19ddb45f8b1353bb4433a99a0
10_3390_computation9020021
GroupedDBID 5VS
8FE
8FG
AADQD
AAFWJ
AAYXX
ABUWG
ADBBV
ADMLS
AFFHD
AFKRA
AFPKN
AFZYC
ALMA_UNASSIGNED_HOLDINGS
ARAPS
AZQEC
BCNDV
BENPR
BGLVJ
BPHCQ
CCPQU
CITATION
DWQXO
GNUQQ
GROUPED_DOAJ
HCIFZ
IAO
K6V
K7-
KQ8
MODMG
M~E
OK1
P62
PHGZM
PHGZT
PIMPY
PQGLB
PQQKQ
PROAC
ID FETCH-LOGICAL-c357t-d7d38fee577eab77b7c6f20faeeb27d507cbe14e75166472ef60bb58e0ffccaa3
IEDL.DBID DOA
ISICitedReferencesCount 12
ISICitedReferencesURI http://www.webofscience.com/api/gateway?GWVersion=2&SrcApp=Summon&SrcAuth=ProQuest&DestLinkType=CitingArticles&DestApp=WOS_CPL&KeyUT=000622366100001&url=https%3A%2F%2Fcvtisr.summon.serialssolutions.com%2F%23%21%2Fsearch%3Fho%3Df%26include.ft.matches%3Dt%26l%3Dnull%26q%3D
ISSN 2079-3197
IngestDate Fri Oct 03 12:48:30 EDT 2025
Tue Nov 18 22:22:18 EST 2025
Sat Nov 29 07:13:17 EST 2025
IsDoiOpenAccess true
IsOpenAccess true
IsPeerReviewed true
IsScholarly true
Issue 2
Language English
LinkModel DirectLink
MergedId FETCHMERGED-LOGICAL-c357t-d7d38fee577eab77b7c6f20faeeb27d507cbe14e75166472ef60bb58e0ffccaa3
ORCID 0000-0003-2344-2576
0000-0003-4948-458X
OpenAccessLink https://doaj.org/article/e23afcf19ddb45f8b1353bb4433a99a0
ParticipantIDs doaj_primary_oai_doaj_org_article_e23afcf19ddb45f8b1353bb4433a99a0
crossref_primary_10_3390_computation9020021
crossref_citationtrail_10_3390_computation9020021
PublicationCentury 2000
PublicationDate 2021-02-01
PublicationDateYYYYMMDD 2021-02-01
PublicationDate_xml – month: 02
  year: 2021
  text: 2021-02-01
  day: 01
PublicationDecade 2020
PublicationTitle Computation
PublicationYear 2021
Publisher MDPI AG
Publisher_xml – name: MDPI AG
References Muller (ref_15) 2020; 108
Moroz (ref_28) 2018; 316
ref_14
ref_13
ref_35
ref_12
ref_11
Blinn (ref_24) 1997; 17
ref_33
ref_10
ref_32
ref_31
ref_30
Bruguera (ref_18) 2020; 69
ref_19
ref_17
ref_39
ref_16
ref_38
ref_37
Horyachyy (ref_26) 2019; 18
Lemaitre (ref_8) 2017; 79
Allie (ref_1) 2005; 22
Muller (ref_21) 1999; 5
Tisserand (ref_23) 2005; 54
ref_25
Schulte (ref_22) 1999; 48
ref_20
Hsieh (ref_36) 2015; 10
ref_40
ref_3
ref_2
ref_29
ref_27
ref_9
ref_5
Janhunen (ref_34) 2013; 78
ref_4
ref_7
ref_6
References_xml – ident: ref_7
– ident: ref_9
– volume: 78
  start-page: 645
  year: 2013
  ident: ref_34
  article-title: Novel detector implementations for 3G LTE downlink and uplink
  publication-title: Analog. Integr. Circuits Signal Process.
– ident: ref_5
– ident: ref_17
  doi: 10.1007/978-3-319-76526-6
– ident: ref_35
  doi: 10.1109/ISCE.2015.7177775
– ident: ref_33
  doi: 10.1109/ICAEE.2014.6838433
– ident: ref_11
– ident: ref_29
  doi: 10.3390/e23010086
– ident: ref_30
  doi: 10.1109/ICPP.2017.52
– ident: ref_16
– volume: 18
  start-page: 461
  year: 2019
  ident: ref_26
  article-title: Simple effective fast inverse square root algorithm with two magic constants
  publication-title: Int. J. Comput.
  doi: 10.47839/ijc.18.4.1616
– ident: ref_39
– ident: ref_40
– volume: 17
  start-page: 80
  year: 1997
  ident: ref_24
  article-title: Floating-point tricks
  publication-title: IEEE Eng. Med. Boil. Mag.
– volume: 316
  start-page: 245
  year: 2018
  ident: ref_28
  article-title: Fast calculation of inverse square root with the use of magic constant–analytical approach
  publication-title: Appl. Math. Comput.
  doi: 10.1016/j.amc.2017.08.025
– ident: ref_37
  doi: 10.1109/VLSID.2017.60
– ident: ref_14
– volume: 54
  start-page: 319
  year: 2005
  ident: ref_23
  article-title: Multipartite table methods
  publication-title: IEEE Trans. Comput.
  doi: 10.1109/TC.2005.54
– volume: 10
  start-page: 219
  year: 2015
  ident: ref_36
  article-title: A UWB Radar Signal Processing Platform for Real-Time Human Respiratory Feature Extraction Based on Four-Segment Linear Waveform Model
  publication-title: IEEE Trans. Biomed. Circuits Syst.
  doi: 10.1109/TBCAS.2014.2376956
– volume: 22
  start-page: 93
  year: 2005
  ident: ref_1
  article-title: A root of less evil digital signal processing
  publication-title: IEEE Signal Process. Mag.
  doi: 10.1109/MSP.2005.1406500
– ident: ref_3
  doi: 10.1109/DEVIC.2017.8073975
– volume: 5
  start-page: 279
  year: 1999
  ident: ref_21
  article-title: A Few Results on Table-Based Methods
  publication-title: Dev. Reliab. Comput.
  doi: 10.1023/A:1009984523264
– ident: ref_32
  doi: 10.1109/IDAACS.2019.8924302
– ident: ref_6
– volume: 69
  start-page: 274
  year: 2020
  ident: ref_18
  article-title: Low Latency Floating-Point Division and Square Root Unit
  publication-title: IEEE Trans. Comput.
  doi: 10.1109/TC.2019.2947899
– ident: ref_25
– ident: ref_4
– ident: ref_31
– ident: ref_27
– ident: ref_2
– ident: ref_20
  doi: 10.1201/b17296
– ident: ref_12
– ident: ref_10
– volume: 48
  start-page: 842
  year: 1999
  ident: ref_22
  article-title: Approximating elementary functions with symmetric bipartite tables
  publication-title: IEEE Trans. Comput.
  doi: 10.1109/12.795125
– volume: 108
  start-page: 2136
  year: 2020
  ident: ref_15
  article-title: Elementary Functions and Approximate Computing
  publication-title: Proc. IEEE
  doi: 10.1109/JPROC.2020.2991885
– ident: ref_38
  doi: 10.1109/IDAACS-SWS.2018.8525803
– ident: ref_13
– ident: ref_19
– volume: 79
  start-page: 1
  year: 2017
  ident: ref_8
  article-title: Cholesky factorization on SIMD multi-core architectures
  publication-title: J. Syst. Arch.
  doi: 10.1016/j.sysarc.2017.06.005
SSID ssj0000913820
Score 2.2199273
Snippet Many low-cost platforms that support floating-point arithmetic, such as microcontrollers and field-programmable gate arrays, do not include fast hardware or...
SourceID doaj
crossref
SourceType Open Website
Enrichment Source
Index Database
StartPage 21
SubjectTerms algorithm design and analysis
elementary function approximation
fast inverse square root algorithm
fused multiply–add
IEEE 754 standard
Newton–Raphson method
Title Modified Fast Inverse Square Root and Square Root Approximation Algorithms: The Method of Switching Magic Constants
URI https://doaj.org/article/e23afcf19ddb45f8b1353bb4433a99a0
Volume 9
WOSCitedRecordID wos000622366100001&url=https%3A%2F%2Fcvtisr.summon.serialssolutions.com%2F%23%21%2Fsearch%3Fho%3Df%26include.ft.matches%3Dt%26l%3Dnull%26q%3D
hasFullText 1
inHoldings 1
isFullTextHit
isPrint
journalDatabaseRights – providerCode: PRVAON
  databaseName: DOAJ Directory of Open Access Journals
  customDbUrl:
  eissn: 2079-3197
  dateEnd: 99991231
  omitProxy: false
  ssIdentifier: ssj0000913820
  issn: 2079-3197
  databaseCode: DOA
  dateStart: 20130101
  isFulltext: true
  titleUrlDefault: https://www.doaj.org/
  providerName: Directory of Open Access Journals
– providerCode: PRVHPJ
  databaseName: ROAD: Directory of Open Access Scholarly Resources
  customDbUrl:
  eissn: 2079-3197
  dateEnd: 99991231
  omitProxy: false
  ssIdentifier: ssj0000913820
  issn: 2079-3197
  databaseCode: M~E
  dateStart: 20130101
  isFulltext: true
  titleUrlDefault: https://road.issn.org
  providerName: ISSN International Centre
– providerCode: PRVPQU
  databaseName: Advanced Technologies & Aerospace Database
  customDbUrl:
  eissn: 2079-3197
  dateEnd: 99991231
  omitProxy: false
  ssIdentifier: ssj0000913820
  issn: 2079-3197
  databaseCode: P5Z
  dateStart: 20130301
  isFulltext: true
  titleUrlDefault: https://search.proquest.com/hightechjournals
  providerName: ProQuest
– providerCode: PRVPQU
  databaseName: Computer Science Database
  customDbUrl:
  eissn: 2079-3197
  dateEnd: 99991231
  omitProxy: false
  ssIdentifier: ssj0000913820
  issn: 2079-3197
  databaseCode: K7-
  dateStart: 20130301
  isFulltext: true
  titleUrlDefault: http://search.proquest.com/compscijour
  providerName: ProQuest
– providerCode: PRVPQU
  databaseName: ProQuest Central
  customDbUrl:
  eissn: 2079-3197
  dateEnd: 99991231
  omitProxy: false
  ssIdentifier: ssj0000913820
  issn: 2079-3197
  databaseCode: BENPR
  dateStart: 20130301
  isFulltext: true
  titleUrlDefault: https://www.proquest.com/central
  providerName: ProQuest
– providerCode: PRVPQU
  databaseName: ProQuest Publicly Available Content
  customDbUrl:
  eissn: 2079-3197
  dateEnd: 99991231
  omitProxy: false
  ssIdentifier: ssj0000913820
  issn: 2079-3197
  databaseCode: PIMPY
  dateStart: 20130301
  isFulltext: true
  titleUrlDefault: http://search.proquest.com/publiccontent
  providerName: ProQuest
link http://cvtisr.summon.serialssolutions.com/2.0.0/link/0/eLvHCXMwrV1NS8MwGA4yPOhB3FScX-TgQZGytmmbxtscG146xCnsVvKphdnqWj9O_naTtI4NQS9eCi1pad_3afI-8OZ5ADhFvohcKkKHY6ScQBDmUMJ9J6IMS64RIBS3ZhN4PI6nU3KzZPVlesJqeeA6cD3pI6q48ogQLAhVzIxRA2NBgBAlhFq27mKyRKbsHEyMtp5b75JBmtf3uDVJsF9LXNuZsLISLQn225VltA22mpIQ9utXaYM1mXfAZrLQUy07oN38giU8a3Siz3dAmRQiU7qEhCNaVtAoZsxLCScvOusS3hZFBWkuVs77RkH8I6u3K8L-7KGYZ9XjU3kJNVxgYt2kYaHg5D2rbJMlTKieGuGgriKrchfcj4Z3g2un8VBwOApx5QgsUKykDDGWOvyYYR4p31VUakqNha4GOZNeIHHoRUZJXqrIZSyMpauUTi5Fe6CVF7ncB5B7gTIFEmVuHISYxyH3FImpIj4zrKULvO94prwRGDc-F7NUEw2Tg_RnDrrgYnHPcy2v8evoK5OmxUgjjW0vaMCkDWDSvwBz8B8POQQbvmluse3bR6BVzV_lMVjnb1VWzk8sFvUx-Rx-AckY61M
linkProvider Directory of Open Access Journals
openUrl ctx_ver=Z39.88-2004&ctx_enc=info%3Aofi%2Fenc%3AUTF-8&rfr_id=info%3Asid%2Fsummon.serialssolutions.com&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&rft.genre=article&rft.atitle=Modified+Fast+Inverse+Square+Root+and+Square+Root+Approximation+Algorithms%3A+The+Method+of+Switching+Magic+Constants&rft.jtitle=Computation&rft.au=Moroz%2C+Leonid+V.&rft.au=Samotyy%2C+Volodymyr+V.&rft.au=Horyachyy%2C+Oleh+Y.&rft.date=2021-02-01&rft.issn=2079-3197&rft.eissn=2079-3197&rft.volume=9&rft.issue=2&rft.spage=21&rft_id=info:doi/10.3390%2Fcomputation9020021&rft.externalDBID=n%2Fa&rft.externalDocID=10_3390_computation9020021
thumbnail_l http://covers-cdn.summon.serialssolutions.com/index.aspx?isbn=/lc.gif&issn=2079-3197&client=summon
thumbnail_m http://covers-cdn.summon.serialssolutions.com/index.aspx?isbn=/mc.gif&issn=2079-3197&client=summon
thumbnail_s http://covers-cdn.summon.serialssolutions.com/index.aspx?isbn=/sc.gif&issn=2079-3197&client=summon