Single-precision floating-point format

Single-precision floating-point format (sometimes called FP32 or float32) is a computer number format, usually occupying 32 bits in computer memory; it represents a wide dynamic range of numeric values by using a floating radix point.

A floating-point variable can represent a wider range of numbers than a fixed-point variable of the same bit width at the cost of precision. A signed 32-bit integer variable has a maximum value of 231 − 1 = 2,147,483,647, whereas an IEEE 754 32-bit base-2 floating-point variable has a maximum value of (2 − 2−23) × 2127 ≈ 3.4028235 × 1038. All integers with seven or fewer decimal digits, and any 2n for a whole number −149 ≤ n ≤ 127, can be converted exactly into an IEEE 754 single-precision floating-point value.

In the IEEE 754 standard, the 32-bit base-2 format is officially referred to as binary32; it was called single in IEEE 754-1985. IEEE 754 specifies additional floating-point types, such as 64-bit base-2 double precision and, more recently, base-10 representations.

One of the first programming languages to provide single- and double-precision floating-point data types was Fortran. Before the widespread adoption of IEEE 754-1985, the representation and properties of floating-point data types depended on the computer manufacturer and computer model, and upon decisions made by programming-language designers. E.g., GW-BASIC's single-precision data type was the 32-bit MBF floating-point format.

Single precision is termed REAL in Fortran;[1] SINGLE-FLOAT in Common Lisp;[2] float in C, C++, C# and Java;[3] Float in Haskell[4] and Swift;[5] and Single in Object Pascal (Delphi), Visual Basic, and MATLAB. However, float in Python, Ruby, PHP, and OCaml and single in versions of Octave before 3.2 refer to double-precision numbers. In most implementations of PostScript, and some embedded systems, the only supported precision is single.

IEEE 754 standard: binary32

The IEEE 754 standard specifies a binary32 as having:

This gives from 6 to 9 significant decimal digits precision. If a decimal string with at most 6 significant digits is converted to the IEEE 754 single-precision format, giving a normal number, and then converted back to a decimal string with the same number of digits, the final result should match the original string. If an IEEE 754 single-precision number is converted to a decimal string with at least 9 significant digits, and then converted back to single-precision representation, the final result must match the original number.[6]

The sign bit determines the sign of the number, which is the sign of the significand as well. The exponent field is an 8-bit unsigned integer from 0 to 255, in biased form: a value of 127 represents the actual exponent zero. Exponents range from −126 to +127 (thus 1 to 254 in the exponent field), because the biased exponent values 0 (all 0s) and 255 (all 1s) are reserved for special numbers (subnormal numbers, signed zeros, infinities, and NaNs).

The true significand of normal numbers includes 23 fraction bits to the right of the binary point and an implicit leading bit (to the left of the binary point) with value 1. Subnormal numbers and zeros (which are the floating-point numbers smaller in magnitude than the least positive normal number) are represented with the biased exponent value 0, giving the implicit leading bit the value 0. Thus only 23 fraction bits of the significand appear in the memory format, but the total precision is 24 bits (equivalent to log10(224) ≈ 7.225 decimal digits).

The bits are laid out as follows:

The real value assumed by a given 32-bit binary32 data with a given sign, biased exponent e (the 8-bit unsigned integer), and a 23-bit fraction is

,

which yields

In this example:

  • ,
  • ,
  • ,
  • ,
  • .

thus:

  • .

Note:

  • ,
  • ,
  • ,
  • .

Exponent encoding

The single-precision binary floating-point exponent is encoded using an offset-binary representation, with the zero offset being 127; also known as exponent bias in the IEEE 754 standard.

  • Emin = 01H−7FH = −126
  • Emax = FEH−7FH = 127
  • Exponent bias = 7FH = 127

Thus, in order to get the true exponent as defined by the offset-binary representation, the offset of 127 has to be subtracted from the stored exponent.

The stored exponents 00H and FFH are interpreted specially.

Exponent fraction = 0 fraction ≠ 0 Equation
00H = 000000002 ±zero subnormal number
01H, ..., FEH = 000000012, ..., 111111102 normal value
FFH = 111111112 ±infinity NaN (quiet, signalling)

The minimum positive normal value is and the minimum positive (subnormal) value is .

Converting decimal to binary32

In general, refer to the IEEE 754 standard itself for the strict conversion (including the rounding behaviour) of a real number into its equivalent binary32 format.

Here we can show how to convert a base-10 real number into an IEEE 754 binary32 format using the following outline:

  • Consider a real number with an integer and a fraction part such as 12.375
  • Convert and normalize the integer part into binary
  • Convert the fraction part using the following technique as shown here
  • Add the two results and adjust them to produce a proper final conversion

Conversion of the fractional part: Consider 0.375, the fractional part of 12.375. To convert it into a binary fraction, multiply the fraction by 2, take the integer part and repeat with the new fraction by 2 until a fraction of zero is found or until the precision limit is reached which is 23 fraction digits for IEEE 754 binary32 format.

, the integer part represents the binary fraction digit. Re-multiply 0.750 by 2 to proceed
, fraction = 0.011, terminate

We see that can be exactly represented in binary as . Not all decimal fractions can be represented in a finite digit binary fraction. For example, decimal 0.1 cannot be represented in binary exactly, only approximated. Therefore:

Since IEEE 754 binary32 format requires real values to be represented in format (see Normalized number, Denormalized number), 1100.011 is shifted to the right by 3 digits to become

Finally we can see that:

From which we deduce:

  • The exponent is 3 (and in the biased form it is therefore )
  • The fraction is 100011 (looking to the right of the binary point)

From these we can form the resulting 32-bit IEEE 754 binary32 format representation of 12.375:

Note: consider converting 68.123 into IEEE 754 binary32 format: Using the above procedure you expect to get with the last 4 bits being 1001. However, due to the default rounding behaviour of IEEE 754 format, what you get is , whose last 4 bits are 1010.

Example 1: Consider decimal 1. We can see that:

From which we deduce:

  • The exponent is 0 (and in the biased form it is therefore
  • The fraction is 0 (looking to the right of the binary point in 1.0 is all )

From these we can form the resulting 32-bit IEEE 754 binary32 format representation of real number 1:

Example 2: Consider a value 0.25. We can see that:

From which we deduce:

  • The exponent is −2 (and in the biased form it is )
  • The fraction is 0 (looking to the right of binary point in 1.0 is all zeroes)

From these we can form the resulting 32-bit IEEE 754 binary32 format representation of real number 0.25:

Example 3: Consider a value of 0.375. We saw that

Hence after determining a representation of 0.375 as we can proceed as above:

  • The exponent is −2 (and in the biased form it is )
  • The fraction is 1 (looking to the right of binary point in 1.1 is a single )

From these we can form the resulting 32-bit IEEE 754 binary32 format representation of real number 0.375:

Converting binary32 to decimal

If the binary32 value, 41C80000 in this example, is in hexadecimal we first convert it to binary:

then we break it down into three parts: sign bit, exponent, and significand.

  • Sign bit:
  • Exponent:
  • Significand:

We then add the implicit 24th bit to the significand:

  • Significand:

and decode the exponent value by subtracting 127:

  • Raw exponent:
  • Decoded exponent:

Each of the 24 bits of the significand (including the implicit 24th bit), bit 23 to bit 0, represents a value, starting at 1 and halves for each bit, as follows:

bit 23 = 1
bit 22 = 0.5
bit 21 = 0.25
bit 20 = 0.125
bit 19 = 0.0625
bit 18 = 0.03125
bit 17 = 0.015625
.
.
bit 6 = 0.00000762939453125
bit 5 = 0.000003814697265625
bit 4 = 0.0000019073486328125
bit 3 = 0.00000095367431640625
bit 2 = 0.000000476837158203125
bit 1 = 0.0000002384185791015625
bit 0 = 0.00000011920928955078125

The significand in this example has three bits set: bit 23, bit 22, and bit 19. We can now decode the significand by adding the values represented by these bits.

  • Decoded significand:

Then we need to multiply with the base, 2, to the power of the exponent, to get the final result:

Thus

This is equivalent to:

where s is the sign bit, x is the exponent, and m is the significand.

Precision limitations on decimal values (between 1 and 16777216)

  • Decimals between 1 and 2: fixed interval 2−23 (1+2−23 is the next largest float after 1)
  • Decimals between 2 and 4: fixed interval 2−22
  • Decimals between 4 and 8: fixed interval 2−21
  • ...
  • Decimals between 2n and 2n+1: fixed interval 2n-23
  • ...
  • Decimals between 222=4194304 and 223=8388608: fixed interval 2−1=0.5
  • Decimals between 223=8388608 and 224=16777216: fixed interval 20=1

Precision limitations on integer values

  • Integers between 0 and 16777216 can be exactly represented (also applies for negative integers between −16777216 and 0)
  • Integers between 224=16777216 and 225=33554432 round to a multiple of 2 (even number)
  • Integers between 225 and 226 round to a multiple of 4
  • ...
  • Integers between 2n and 2n+1 round to a multiple of 2n-23
  • ...
  • Integers between 2127 and 2128 round to a multiple of 2104
  • Integers greater than or equal to 2128 are rounded to "infinity".

Notable single-precision cases

These examples are given in bit representation, in hexadecimal and binary, of the floating-point value. This includes the sign, (biased) exponent, and significand.

0 00000000 000000000000000000000012 = 0000 000116 = 2−126 × 2−23 = 2−149 ≈ 1.4012984643 × 10−45
                                                   (smallest positive subnormal number)
0 00000000 111111111111111111111112 = 007f ffff16 = 2−126 × (1 − 2−23) ≈ 1.1754942107 ×10−38
                                                   (largest subnormal number)
0 00000001 000000000000000000000002 = 0080 000016 = 2−126 ≈ 1.1754943508 × 10−38
                                                   (smallest positive normal number)
0 11111110 111111111111111111111112 = 7f7f ffff16 = 2127 × (2 − 2−23) ≈ 3.4028234664 × 1038
                                                   (largest normal number)
0 01111110 111111111111111111111112 = 3f7f ffff16 = 1 − 2−24 ≈ 0.999999940395355225
                                                   (largest number less than one)
0 01111111 000000000000000000000002 = 3f80 000016 = 1 (one)
0 01111111 000000000000000000000012 = 3f80 000116 = 1 + 2−23 ≈ 1.00000011920928955
                                                   (smallest number larger than one)
1 10000000 000000000000000000000002 = c000 000016 = −2
0 00000000 000000000000000000000002 = 0000 000016 = 0
1 00000000 000000000000000000000002 = 8000 000016 = −0
                                  
0 11111111 000000000000000000000002 = 7f80 000016 = infinity
1 11111111 000000000000000000000002 = ff80 000016 = −infinity
                                  
0 10000000 100100100001111110110112 = 4049 0fdb16 ≈ 3.14159274101257324 ≈ π ( pi )
0 01111101 010101010101010101010112 = 3eaa aaab16 ≈ 0.333333343267440796 ≈ 1/3
                                  
x 11111111 100000000000000000000012 = ffc0 000116 = qNaN (on x86 and ARM processors)
x 11111111 000000000000000000000012 = ff80 000116 = sNaN (on x86 and ARM processors)

By default, 1/3 rounds up, instead of down like double precision, because of the even number of bits in the significand. The bits of 1/3 beyond the rounding point are 1010... which is more than 1/2 of a unit in the last place.

Encodings of qNaN and sNaN are not specified in IEEE 754 and implemented differently on different processors. The x86 family and the ARM family processors use the most significant bit of the significand field to indicate a quiet NaN. The PA-RISC processors use the bit to indicate a signaling NaN.

Optimizations

The design of floating-point format allows various optimisations, resulting from the easy generation of a base-2 logarithm approximation from an integer view of the raw bit pattern. Integer arithmetic and bit-shifting can yield an approximation to reciprocal square root (fast inverse square root), commonly required in computer graphics.

See also

References

  1. ^ "REAL Statement". scc.ustc.edu.cn. Archived from the original on 2021-02-24. Retrieved 2013-02-28.
  2. ^ "CLHS: Type SHORT-FLOAT, SINGLE-FLOAT, DOUBLE-FLOAT..." www.lispworks.com.
  3. ^ "Primitive Data Types". Java Documentation.
  4. ^ "6 Predefined Types and Classes". haskell.org. 20 July 2010.
  5. ^ "Float". Apple Developer Documentation.
  6. ^ William Kahan (1 October 1997). "Lecture Notes on the Status of IEEE Standard 754 for Binary Floating-Point Arithmetic" (PDF). p. 4. Archived from the original (PDF) on 8 February 2012.

Read other articles:

Keely Shaye Smith BrosnanLahirKeely Shaye SmithNama lainKeely BrosnanPekerjaanPresenter dan wartawan TVTahun aktif1986—kiniSuami/istriPierce Brosnan (2001—kini) Keely Shaye Smith (lahir 25 September 1963, juga dikenal sebagai Keely Shaye Brosnan) adalah seorang wartawan Amerika Serikat, penulis, dan presenter televisi/koresponden. Dia menikah dengan Pierce Brosnan. Smith telah malang melintang di beberapa stasiun televisi AS, di antaranya NBC, CBS, dan ABC sejak tahun 1994 samp...

 

2012 fighting crossover video game 2012 video gamePlayStation All-Stars Battle RoyaleNorth American PlayStation 3 cover art featuring (clockwise from upper center) Kratos, Raiden, Ratchet & Clank, Fat Princess, Sackboy, Sly Cooper, Big Daddy, and Nathan DrakeDeveloper(s)SuperBot Entertainment[a]Publisher(s)Sony Computer EntertainmentDirector(s)Omar KendallProducer(s)Chan ParkDesigner(s)Seth KillianComposer(s)John KingEngineBluepoint EnginePlatform(s)PlayStation 3, PlayStation Vita...

 

Administrative tribunal in Canada Canadian Human Rights TribunalTribunal canadien des droits de la personneEstablished1977Composition methodAppointment by the Governor in Council on the recommendation of the minister of justice and attorney generalAuthorized byParliament of Canada via the Canadian Human Rights ActAppeals toFederal CourtNumber of positions15ChairpersonCurrentlyJennifer KhuranaSince2021 The Canadian Human Rights Tribunal (French: Tribunal canadien des droits de la personne) is ...

Sukhoi Superjet 100Sukhoi Superjet 100TipePesawat penumpang regionalPerancangSukhoi Civil Aircraft (UAC)Terbang perdana19 Mei 2008[1]Diperkenalkan21 April 2011 dengan ArmaviaPengguna utamaAeroflot[2]Yamal AirlinesAzimuthGazpromaviaTahun produksi2007–sekarangJumlah produksi175 (per 15 Juli 2019) [3]Biaya programUS$1,4 milyarHarga satuan$23-25 juta[4] Sukhoi Superjet 100 (Bahasa Rusia: Сухой Суперджет 100, disebut juga SU-95) merupakan s...

 

豪栄道 豪太郎 場所入りする豪栄道基礎情報四股名 澤井 豪太郎→豪栄道 豪太郎本名 澤井 豪太郎愛称 ゴウタロウ、豪ちゃん、GAD[1][2]生年月日 (1986-04-06) 1986年4月6日(38歳)出身 大阪府寝屋川市身長 183cm体重 160kgBMI 47.26所属部屋 境川部屋得意技 右四つ・出し投げ・切り返し・外掛け・首投げ・右下手投げ成績現在の番付 引退最高位 東大関生涯戦歴 696勝493敗...

 

Флаг Королевства Валенсия Королевство Валенсия (кат. Regne de València, исп. Reino de Valencia) — составная и неделимая территория, принадлежащая короне Арагона, но не являющаяся юридически зависимой от королевства Арагон. Валенсия получила статус королевства в ходе Реконкисты, к...

School of thought in social sciences This article includes a list of general references, but it lacks sufficient corresponding inline citations. Please help to improve this article by introducing more precise citations. (April 2009) (Learn how and when to remove this message) Part of a series onGreen politics Core topics Climate change litigation Fossil fuels lobby Green politics Green party List of topics Politics of climate change Four pillars Ecological wisdom Social justice Grassroots dem...

 

Iranian religion founded by Zoroaster This article needs more complete citations for verification. Please help add missing citation information so that sources are clearly identifiable. (April 2024) (Learn how and when to remove this message) ZoroastrianismAtash Behram at the Fire Temple of Yazd in IranTypeUniversal religionClassificationIranianScriptureAvestaTheologyDualistic[1][2]LanguageAvestanFounderZoroaster (traditional)Originc. 2nd millennium BCE Iranian PlateauSe...

 

  提示:此条目页的主题不是蘇慧恩。 蘇慧音个人信息全名Minnie Soo Wai Yam國籍 中华人民共和国(香港)出生 (1998-04-13) 1998年4月13日(26歲) 香港最高排名第25名(2018年2月)[1] 奖牌记录 女子乒乓球 代表 中國香港 奧林匹克運動會 2020年 東京 女子團體 世界乒乓球錦標賽 2018年 哈爾姆斯塔德 女子團體 世界杯乒乓球賽 2018年 倫敦 女子團體 亞洲運動會 2018年 ...

Topik artikel ini mungkin tidak memenuhi kriteria kelayakan organisasi dan perusahaan. Harap penuhi kelayakan artikel dengan: menyertakan sumber-sumber tepercaya yang independen terhadap subjek dan sebaiknya hindari sumber-sumber trivial. Jika tidak dipenuhi, artikel ini harus digabungkan, dialihkan ke cakupan yang lebih luas, atau dihapus oleh Pengurus.Cari sumber: Trans Shopping Mall Group – berita · surat kabar · buku · cendekiawan · JSTOR (Juni 202...

 

Sân vận động Banc of CaliforniaKhán đài phía Đông trên Đường FigueroaSân vận động Banc of CaliforniaVị trí ở Vùng đô thị L.A.Xem bản đồ vùng đô thị Los AngelesSân vận động Banc of CaliforniaVị trí ở CaliforniaXem bản đồ CaliforniaSân vận động Banc of CaliforniaVị trí ở Hoa KỳXem bản đồ Hoa KỳĐịa chỉ3939 Đường South FigueroaVị tríLos Angeles, California, Hoa KỳTọa độ34°00′47″B 118°17′06″...

 

Kelenteng Hok Tek Bio. Kelenteng Hok Tek Bio atau Klenteng Amurvabhumi (Hanzi: 福德廟) yang berada di Jalan Letjen Sukowati merupakan saksi sejarah masuknya ajaran agama Budha di Kota Salatiga. Dan dalam perjalanannya, kelenteng Hok Tiek Bio ini pun menjadi simbol dari keberadaan penganut Tri Dharma, yakni kombinasi antara agama Budha, Khong Hu Cu dan Taoisme.[1][2][3][4][5][6] Masuknya pengaruh ajaran Budha sendiri sebenarnya sudah terja...

Artikel ini membutuhkan rujukan tambahan agar kualitasnya dapat dipastikan. Mohon bantu kami mengembangkan artikel ini dengan cara menambahkan rujukan ke sumber tepercaya. Pernyataan tak bersumber bisa saja dipertentangkan dan dihapus.Cari sumber: Nana Sudjana – berita · surat kabar · buku · cendekiawan · JSTOR (Juli 2024) Nana SudjanaPotret sebagai Penjabat Gubernur Jawa Tengah Penjabat Gubernur Jawa TengahPetahanaMulai menjabat 5 September 2023Pr...

 

Revolución de Xinhai Parte de movimientos anti-Qing La Calle Nanjing en Shanghái después del Levantamiento de Shanghai, adornada con las banderas de las Cinco razas bajo una unión utilizadas por los revolucionarios en Shanghái y el norte de ChinaFecha 10 de octubre de 1911-12 de febrero de 1912Lugar ChinaCasus belli Levantamiento de WuchangResultado Derrota de la dinastía Qing y establecimiento de la República de ChinaConsecuencias Caída del Imperio chino Abdicación del emperador Xua...

 

H&K MP7 H&K MP7A2概要種類 PDW製造国 ドイツ設計・製造 ヘッケラー&コッホ性能口径 4.6 mm銃身長 180 mm[1]ライフリング 4条右回り[1]使用弾薬 4.6x30mm弾装弾数 20・30・40発[2][3]作動方式 ショートストロークピストン式マイクロ・ロッキング・ラグ回転ボルト閉鎖全長 415 mm (ストック展開時:638 mm)[2][3][4]重量 MP7A1 : 1.9 kg[...

15th/16th-century Italian philosopher and priest For the saint, see Saint Cajetan. The ReverendThomas de Vio CajetanOPMartin Luther in front of Cardinal Cajetan by Ferdinand PauwelsBorn(1469-02-20)20 February 1469Gaeta, Kingdom of NaplesDied9 August 1534(1534-08-09) (aged 65)Rome, Papal StatesAlma materUniversity of PaduaNotable workSummula Caietani.EraMedieval philosophyRegion Western philosophy Italian philosophy SchoolThomismMain interestsMetaphysicsTheologyAnalogy Thomas Cajetan...

 

Chinese communist leader (1904–1997) Deng Xiaoping邓小平Deng during a visit to the United States in 1979Chairman of the Central Advisory CommissionIn office13 September 1982 – 2 November 1987PresidentLi XiannianPremierZhao ZiyangDeputy Bo Yibo Xu Shiyou Tan Zhenlin Li Weihan Wang Zhen Song Renqiong General Secretary Hu Yaobang Zhao Ziyang (acting) Preceded byOffice establishedSucceeded byChen YunChairman of the Central Military CommissionIn officeParty Commission: 28 June 1981...

 

Ellis Island Medal of HonorEllis Island Medal of HonorNational Ethnic Coalition of OrganizationsTipologiaMedaglia di riconoscimento Statusattivo IstituzioneEllis Island, 1986 GradiMedaglia (classe unica) Nastro della medaglia Modifica dati su Wikidata · Manuale La Ellis Island Medal of Honor (Medaglia d'onore di Ellis Island) è una decorazione concessa negli Stati Uniti d'America dalla National Ethnic Coalition of Organizations (NECO). Essa ha lo scopo di rendere omaggio a quegli immig...

يفتقر محتوى هذه المقالة إلى الاستشهاد بمصادر. فضلاً، ساهم في تطوير هذه المقالة من خلال إضافة مصادر موثوق بها. أي معلومات غير موثقة يمكن التشكيك بها وإزالتها. (مارس 2022) معركة بيروذ جزء من الفتح الإسلامي لخوزستان  معلومات عامة التاريخ 23 هـ - 643/4 م الموقع ذبيرو ، بالقرب من ا...

 

Axiom of set theory This article is about the mathematical concept. For the band, see Axiom of Choice (band). Illustration of the axiom of choice, with each set Si represented as a jar and its elements represented as marbles. Each element xi is represented as a marble on the right. Colors are used to suggest a functional association of marbles after adopting the choice axiom. The existence of such a choice function is in general independent of ZF for collections of infinite cardinality, even ...