Hi there!

I am a student studying computer science.

컴퓨터 구조

컴퓨터 구조 8장 - FP

만능성구 2020. 6. 20. 17:11
728x90

실수는 우리가 컴퓨터에서 계산을 위해 많이 사용한다.

N bits로 수를 표현하는 방법

 

Unsigned integers:

            0 to 2^N – 1 (for N=32, 2^N–1 = 4,294,967,295)

– Signed Integers (Two’s Complement)

           -2^(N-1) to 2^(N-1) - 1 (for N=32, 2^(N-1) = 2,147,483,648)

 

- 아주 큰 수 (seconds/millennium)

             Þ 31,556,926,00010 (3.155692610 x 10^10)

- 아주 작은 수 (Bohr radius)

             Þ 0.000000000052917710m (5.2917710 x 10^-11)


‘fixed binary point’,

range is fixed, 표현할 수 있는 수가 너무 작다


– 10.10102 = 1x2^1 + 1x2^-1 + 1x2^-3 = 2.62510

– 0 to 3.9375 (almost 4)

Scientific Notation


Seientific Notation 과학 계산 표현 방법

Decimal

정규환된 형태로 소수점 위에 정수 하나만 표현

 

– 1/1,000,000,000을 표현하면

          • Normalized: 1.0 x 10^-9

          • Not normalized: 0.1 x 10^-8,10.0 x 10^-10

Binary

 – floating point because the binary point is not fixed

- fixed되어 있지 않고 exponent를 바꾸어서 표현

– Types float(4bytes) and double(8bytes) in C언어

 – Normal format: ±1.xxx…x_2 × 2^yyy…y_2


Floating-Point Standard

IEEE Std 754-1985 에 인증되어 있다.

Single precision (32-bit), Double precision (64-bit)

S: sign bit (0 Þ non-negative, 1 Þ negative)

– Normalize significand: 1.0 ≤ |significand| < 2.0   앞부분의 크기가 이 범위 안에 있도록

         • 항상 1을 가지고 있기 때문에 표현하지 않는다. (hidden bit)

         • Significand is Fraction with the “1.” restored

Exponent: excess representation: actual exponent + Bias **중요

         • Ensures exponent is unsigned

         • Single: Bias = 127; Double: Bias = 1023

            exponet가 항상 양수가 되도록

            integer 실수들의 크기를 비교하기 위해서


Single-Precision Range

Exponents 00000000 and 11111111 reserved

                   0과               무한대             표현하기

 • Smallest value

      – Exponent: 00000001 Þ actual exponent = 1 – 127 = –126

      – Fraction: 000…00 Þ significand = 1.0 – ±1.0 × 2–126 ≈ ±1.2 × 10–38

Largest value

        – Exponent: 11111110 Þ actual exponent = 254 – 127 = +127

         – Fraction: 111…11 Þ significand ≈ 2.0 – ±2.0 × 2+127 ≈ ±3.4 × 10+38

Double-Precision Range

Smallest value : ±1.0 × 2–1022 ≈ ±2.2 × 10–308

Largest value : ±2.0 × 2+1023 ≈ ±1.8 × 10+308

 

Floating-Precision Range

얼마나 정밀하게 표현하는가

– Single: approx 2–23: Equivalent to 23 × log102 ≈ 23 × 0.3 ≈ 6 decimal digits

– Double: approx 2–52: Equivalent to 52 × log102 ≈ 52 × 0.3 ≈ 16 decimal digits


Example

실수 - > bit 

bit -> 실수


 

Infinities and NaNs

 • Exponent = 111...1, Fraction = 000...0

 – ±Infinity

 – 실수를 0으로 나누었을 때 +_ 0, not overflow

– Can be used in subsequent calculations, avoiding need for overflow check

               • X/0 > Y may be a valid comparison 이렇게 사용 무조건 참

Exponent = 111...1, Fraction ≠ 000...0

– Not-a-Number (NaN)

– Indicates illegal or undefined result

               • e.g., 0.0 / 0.0 or sqrt(-4.0)

– Can be used in subsequent calculations

                • op(NaN, X) = NaN


Denormal Numbers

문제 : 0주변에서 gap이 너무 크다.

 

가장 작은 값

          a = 1.0… 2 * 2-126 = 2-126

두번 째 작은 값

          b = 1.000……12 * 2-126 = (1 + 0.00…12) * 2-126 = (1 + 2-23) * 2-126

             = 2-126 + 2-149

 a - 0 = 2-126

 b - a = 2-149

 

해결 아직 exponent =0 이 사용되지 않았다.? , Significand nonzero

fraction에 1이 있다는 가정을 없앤다.

가장 작은 값

          a = 2^-149 (0.000…01_2*2^-126 = 2^-23 *2^-126)

두번 째 작은 값

          b = 2^-148 (0.000…10_2*2^-126 = 2^-22 *2^-126)

 

 – Smallest normal number 평범한..

1.00…02*2-12^6 = (1 )*2-12^6



Floating 에서 덧셈

• Consider a 4-digit decimal example

 – 9.999 × 10^1 + 1.610 × 10^–1

• 1. Align decimal points

        작은 exponent를 옮겨서 자리수를 마쳐준다

              – 9.999 × 10^1 + 0.016 × 10^1

• 2. Add significands

          더한다

              – 9.999 × 10^1 + 0.016 × 10^1 = 10.015 × 10^1

• 3. Normalize result & check for over/underflow

          정규화

                – 1.0015 × 10^2

• 4. Round and renormalize if necessary

           반올림

                 – 1.002 × 10^2

이진수에서 덧셈

• Now consider a 4-digit binary example

– 1.0002 × 2–1 + –1.1102 × 2–2 (0.5 + –0.4375)

• 1. Align binary points

        작은 exponent를 옮겨서 자리수를 마쳐준다

              – 1.0002 × 2–1 + –0.1112 × 2–1

• 2. Add significands

          더한다

               – 1.0002 × 2–1 + –0.1112 × 2–1 = 0.0012 × 2–1

• 3. Normalize result & check for over/underflow

          정규화

                – 1.0002 × 2–4, with no over/underflow

 • 4. Round and renormalize if necessary

           반올림

                 – 1.0002 × 2–4 (no change) = 0.0625

728x90