# Gustavo's IEEE-754 Brain Teaser

DevFeed: [Gustavo's IEEE-754 Brain Teaser](<https://devfeed.tech/articles/gustavo-s-ieee-754-brain-teaser-22064.md>)

Original publisher: [Read original article](<https://www.ardanlabs.com/blog/2013/08/gustavos-ieee-754-brain-teaser.html>)

Published: 2013-08-05T00:00:00Z

Content type: tutorial

Language: en

Sources: [William Kennedy](<https://devfeed.tech/sources/william-kennedy.md>)

Topics: [coding](<https://devfeed.tech/topics/coding.md>), [Math and Logic](<https://devfeed.tech/topics/math-and-logic.md>)

Tags: [ardan-labs](<https://devfeed.tech/tags/ardan-labs.md>), [blog](<https://devfeed.tech/tags/blog.md>), [coding](<https://devfeed.tech/tags/coding.md>), [examples](<https://devfeed.tech/tags/examples.md>), [floating-point](<https://devfeed.tech/tags/floating-point.md>), [go](<https://devfeed.tech/tags/go.md>), [go-programming](<https://devfeed.tech/tags/go-programming.md>), [golang](<https://devfeed.tech/tags/golang.md>), [numbers](<https://devfeed.tech/tags/numbers.md>), [programming](<https://devfeed.tech/tags/programming.md>), [standard](<https://devfeed.tech/tags/standard.md>)

## AI overview

The article breaks down a question about determining whether an IEEE-754 binary floating-point representation corresponds to an integer. It explains binary scientific notation and simplifies the discussion by working with a 32-bit number.

## Source excerpt

Back in June, Gustavo Niemeyer posted the following question on his Labix.org blog: Assume uf is an unsigned integer with 64 bits that holds the IEEE-754 representation for a binary floating point number of that size. How can you tell if uf represents an integer number? I can't talk for you, but I write business applications. I just don't have the background to quickly knock out an answer for a question like this. Fortunately Gustavo posted the logic for the answer. I thought it would be fun to better understand the question and break down his answer. I am going to work with a 32 bit number just to make everything easier. How does the IEEE-754 standard store a floating point number in a binary format? To start I found these two pages: External resource on steve.hollasch.net: http://steve.hollasch.net/cgindex/coding/ieeefloat.html External resource on class.ece.iastate.edu: http://class.ece.iastate.edu/arun/CprE281_F05/ieee754/ie5.html The IEEE-754 specification represents a floating point number in base 2 scientific notation using a special binary format. If you don't know what I mean by base 2 then look at my post on Understanding Type In Go (External resource on ardanlabs.com: https://www.ardanlabs.com/blog/2013/07/understanding-type-in-go.html). Scientific notation is an efficient way of writing very large or small numbers. It works by using a decimal format with a multiplier. Here are some examples: Base 10 Number Scientific Notation Calculation Coefficient Base Exponent Mantissa 700 7e+2 7 * 102 710 2 0 4,900,000,000 4.9e+9 4.9 * 109 4.9 10 9 .9 5362.63 5.36263e+3 5.36263 * 103 5.36263 10 3 .36263 -0.00345 3.45e-3 3.45 * 10-3 3.45 10 -3 .45 0.085 1.36e-4 1.36 * 2-4 1.36 2 -4 .36 In normal scientific notation form there is always just one digit on the left side of the decimal point. For base 10 numbers that digit must be between 1 through 9 and for base 2 numbers that digit can only be 1. The entire number in scientific notation is called the Coefficient. The Ma