Floating-point numbers
도입됨
15:07
사용자 정의 데이터 타입
평범한 문자열 필드는 허구적 데이터를 기꺼이 저장합니다. 차량 유형을 묻고 someone이 Bananas를 입력하면 프로그램은 아무런 불만 없이 이를 수락합니다. 하지만 만약 당신이…
영어 내레이션 · 영어와 중국어 자막 전환 가능
이 수업의 내용
| English | 의미 |
|---|---|
| binary representation | A way of showing a number using only the digits zero and one. |
| repeating fraction | A fraction whose digits continue forever in a repeating pattern. |
| truncated/ˈtrʌŋkeɪtɪd/ | Describes a number shortened by removing digits without rounding. |
| register's | Belonging to a small storage location inside the processor. |
| accumulated error | The total difference from the correct value after small errors build up. |
| floating-point/ˈfləʊtɪŋ pɔɪnt/ | 부동소수점 |
| normalisation/ˌnɔːməlaɪˈzeɪʃn/ | The process of adjusting a mantissa and exponent to use available bits efficiently. |
| approximation errors | Differences between exact values and the close values used to represent them. |
| real numbers | All numbers that can be placed on a continuous number line. |
| scientific notation | A way to write a number as a value multiplied by a power of ten. |
| fields/fiːldz/ | Parts of a database record that each hold one item of data. |
| mantissa/mænˈtɪsə/ | |
| significant digits | Digits that give useful information about the precision of a number. |
| exponent/ekˈspəʊnənt/ | 지수 |
| two's complement/tuːz ˈkɒmplɪmənt/ | A signed binary integer representation in which a negative value is formed by inverting the positive value's bits and adding one within a fixed bit width. |
| binary fraction | A number with binary digits after a binary point. |
| bit/bɪt/ | A binary digit, taking the value zero or one. |
| denary/ˈdiːnəri/ | The base-ten number system, using the digits zero through nine. |
| sign bit/saɪn bɪt/ | The bit in a signed-number representation that indicates or contributes the number's sign. |
| normalised/ˈnɔːməlaɪzd/ | 정규화됨 |
| significant bit | A bit that gives useful information about the value of a number. |
| binary point | The point separating whole-number bits from fractional bits in a binary number. |
| leading zeros | Zeros placed before the first non-zero digit to give a number the required width. |
| maximises precision | Makes a stored value as exact as the available bits allow. |
| precision/prɪˈsɪʒn/ | 정밀도 |
| range/reɪndʒ/ | The set of values that can be represented in a given format. |
| Rounding errors/ˈraʊndɪŋ ˈerəz/ | Differences caused by replacing exact values with nearby values that can be stored. |
| fixed-point/fɪkst pɔɪnt/ | 고정소수점 |
| BCD/ˌbiː siː ˈdiː/ | A way of storing each denary digit separately using four binary digits. |
| Overflow/ˌəʊvəˈfləʊ/ | The condition when a result is too large in magnitude to be represented. |
| Underflow/ˌʌndəˈfləʊ/ | The condition when a nonzero result is too close to zero to be represented. |
| integer/ˈɪntɪdʒə/ | A whole number that may be positive, negative or zero. |
| tolerance/ˈtɒlərəns/ | The largest acceptable difference when comparing two values for near equality. |
600미터를 빗겨 날아간 미사일
- On 25 February 1991 a Patriot battery at Dhahran failed to intercept an incoming missile. Twenty-eight soldiers died.
- The system counted time in tenths of a second, and 0.1 has no exact binary representation: it is a repeating fraction, truncated to the register's width. Each tick lost a fraction of a microsecond.
- After a hundred hours running, the accumulated error was a third of a second, and in a third of a second the target moved 600 metres. The arithmetic was correct at every single step.
- 이 수업에서는 부동소수점 형식, 정규화, 그리고 이러한 현상이 가능하게 하는 근사 오차를 다룹니다.

형식
- 크기가 매우 다른 실수를 저장하기 위해 컴퓨터는 과학적 표기법의 이진 형태를 사용하며 두 개의 필드를 가집니다: 유효숫자인 **mantissa(부동소수점 수)**와 곱해야 할 2의 거듭제곱인 exponent(지수). 둘 다 **두의 보수(two's complement)**로 저장됩니다.
- 부동소수점의mantissa를 이진 fraction으로 읽으세요: 소수점 바로 뒤 첫 번째 비트는 $\tfrac12$, 다음은 $\tfrac14$, 그 다음은 $\tfrac18$에 해당. 따라서
0.1010000은 $\tfrac12 + \tfrac18 = 0.625$입니다. - 지수가
00000010일 때, 즉 $+2$일 때, 해당 값은 $0.625 \times 2^2 = 2.5$입니다.

분수와 2의 거듭제곱

Build a floating-point number
Flip the mantissa and exponent bits to make a value, and check whether it is normalised.
A floating-point number is stored as:
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
value = mantissa × 2^exponent — binary scientific notation, with both parts stored in two's complement.
Match each part of floating-point representation to its role.
난이도 2/5 · 140코인 + 오늘 첫 완료 시 작은 보너스 추가
value = mantissa × 2^exponent; normalising maximises precision; money uses fixed-point/BCD to avoid rounding.
worked example: 이진 수를 진법으로 변환
- 어떤 수의 mantissa가
10110000이고 지수가00000011일 때, 이 수의 진법 값을 구하십시오. - 지수는 $+3$입니다. mantissa가 1로 시작하므로 음수이며 두의 보수 규칙에 따라 읽힙니다:
1.0110000에서 부호 비트는 $-1$의 가치를 가지며 분수 비트들은 $\tfrac14 + \tfrac18 = 0.375$를 더하므로, mantissa는 $-1 + 0.375 = -0.625$입니다. - $\text{number} = -0.625 \times 2^3 = -5.0$.
- 가장 흔한 실수는 음수의 유효숫자를 양수로 잘못 읽는 것입니다. 먼저 부호 비트를 반드시 확인하십시오.

A floating-point number has mantissa 10110000 and exponent 00000011. What is its denary value?
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
The mantissa starts with 1, so it is negative: $-1 + \dfrac{1}{4} + \dfrac{1}{8} = -0.625$. Times $2^{3}$ gives $-5.0$. Reading it as positive is the usual error.
worked example: 십진수에서 이_Handle로 변환
- $+2.5$을 동일한 8비트 유효숫자, 8비트 지수부 형식으로 저장합니다.
- 이진수에서 $2.5 = 10.1$입니다. 2의 거듭제곱을 한 분수로 표기하면: $2.5 = 0.101 \times 2^2$입니다.
- So the mantissa is
01010000, a sign bit of 0 then.101padded with zeros, and the exponent is00000010. - 항상 정형화(normalised)된 형태로 먼저 작성한 후, 두 필드를 그대로 읽어내십시오.

Written as a normalised fraction times a power of two, $2.5 = 0.101 \times 2^{n}$ (the fraction in binary). The exponent $n$ is ____.
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
$2.5$ is $10.1$ in binary; sliding the point two places left gives $0.101$, so the exponent is $2$ and the mantissa is 01010000.
정규화
- 수는 유효숫자의 첫 번째 비트가 이진 소수점 바로 뒤에 위치할 때 **정규화(normalised)**되었다고 합니다. 이는 앞선 불필요한 영점(leading zeros)이 없음을 의미합니다. 양수인 경우 mantissa는
0.1로 시작하고, 음수인 경우1.0로 시작합니다. - 이유: 이는 정밀도를 극대화합니다. 각 유효숫자 비트가 정보(앞선 0이 아닌)를 담당하기 때문입니다.
- 정형화하기 위해 유효숫자를 왼쪽으로 이동하고 지수부를 같은 개수만큼 줄이거나, 오른쪽으로 이동하고 늘립니다. 값은 변하지 않으며, 오직 표현 방식만 바뀝니다.

비트 이동, 지수부 조정, 값 유지

Trading mantissa bits against exponent bits
- 총 비트 수는 고정되어 있으므로 두 필드는 서로 경쟁합니다.
- 유효숫자 비트가 많을수록 정밀도가 높아집니다: 각 값이 더 정확히 저장되어 절사 오류가 작아집니다.
- 지수부 비트가 많을수록 범위가 넓어집니다: 훨씬 크거나 작은 크기의 값을 표현할 수 있지만, 각 값은 더 정밀하지 않게 표현됩니다.
- 한 비트를 한 필드에서 다른 필드로 이동할 때의 효과를 묻는 질문은 바로 이 트레이드오프, 즉 범위와 정밀도의 관계를 정확히 요구합니다.
Normalising a floating-point number
Step through normalisation. Shifting the mantissa to remove wasted leading zeros — and adjusting the exponent to match — keeps the value the same but spends every bit on precision.
Normalising a floating-point number:
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
Normalisation shifts the mantissa so the first significant bit follows the point — every bit then carries information, and the value is unchanged.
Which are true of normalising a floating-point number? Select 모든 that apply.
난이도 2/5 · 140코인 + 오늘 첫 완료 시 작은 보너스 추가
Normalising changes only the representation. The value is unchanged; that is what adjusting the exponent guarantees.
근사값과 그 결과
- 많은 진법 실수들은 이진수에서 정확히 저장될 수 없습니다. $0.1$는 무한 소수 $0.000110011\ldots$이므로 잘려야 하며: 저장된 값은 $0.1$과 유사하지만 결코 같지 않습니다.
- 반올림 오차는 여러 연산을 거치면서 축적되는데, 이것이
0.1 + 0.2가 정확히0.3이 아닌 이유이자 Patriot 미사일의 시계가 drift(편차)를 일으킨 이유입니다. - 따라서 절대 두 실수의 등식을 테스트하지 마십시오:
x = 0.3대신ABS(x - 0.3) < 1e-9를 작성하십시오. 또한 서로 거의 같은 두 값을 뺄 때는 유의하십시오. 이 경우 유효숫자의 대부분이 사라지기 때문입니다. - 정확성이 필수적인 값, 특히 화폐 금액에는 고정소수점(fixed-point) 또는 BCD를 사용하십시오.
Match each change in the bit allocation to its effect.
난이도 2/5 · 140코인 + 오늘 첫 완료 시 작은 보너스 추가
The word size is fixed, so precision and range trade against each other; overflow and underflow are the exponent field running out at each end.
오버플로우와 언더플로우
- 오버플로우는 결과가 지수의 범위를 너무 크게 초과하여 아예 표현할 수 없을 때 발생합니다.
- 언더플로우(underflow) 는 결과가 너무 작아 제로에 너무 가까워 지수부가 더 낮아질 수 없어 제로로 반올림될 때 발생합니다.
- Both are properties of the exponent field's size, which is the other half of the trade-off above.

0.1 cannot be stored exactly in binary (it is a repeating fraction), so 0.1 + 0.2 does not give exactly 0.3 on a computer.
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
The tiny approximation errors add up — which is why money is handled with fixed-point or BCD, not floating-point.
For exact money calculations you should use:
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
Floating-point rounding errors are unacceptable for currency; decimal fixed-point or an appropriate BCD representation can store amounts exactly to the chosen decimal scale.
놓칠 수 있는 점
- The mantissa is a fraction, not an integer: the first bit after the point is a half.
- 1로 시작하는 유효숫자는 음수이며 2의 보수 규칙을 따릅니다. 먼저 해당 비트를 확인하십시오.
- 정형화는 정밀도를 극대화하며, 값 자체를 바꾸거나 숫자를 크게 만들지는 않습니다.
- 유효숫자가 많으면 정밀도, 지수부가 많으면 범위입니다. 오버플러우는 너무 큼, 언더플로우는 너무 작음입니다.
이해했습니다
- 부동 소수점은 $\text{mantissa} \times 2^{\text{exponent}}$를 저장하며 둘 다 이의 보수로 나타냅니다. 가수는 이진 소수입니다.
- 유효숫자를 분수로 reading(2의 보수 if starts with 1)하고 지수부에 해당하는 2의 거듭제곱으로 곱하여 convert합니다.
- 정형化은 첫 유효숫자 비트가 점 바로 다음에 있어 정밀도를 극대화함을 의미하며, 왼쪽으로 이동하면 지수부가 낮아집니다.
- 유효숫자 비트가 많으면 정밀도, 지수부 비트가 많으면 범위; 이_Handle는 많은 실수를 정확히 store할 수 없으므로 절사 오류를 예상하고, 허용 오차(tolerance)로 비교하며, 화폐에는 고정소수점이나 BCD를 사용하십시오.
어떤 문제가 있었나요? 사이트 팀만 이 내용을 볼 수 있습니다.