Posts 🍡 λΆ€λ™μ†Œμˆ˜μ  λ¦¬ν„°λŸ΄
Post
Cancel

🍡 λΆ€λ™μ†Œμˆ˜μ  λ¦¬ν„°λŸ΄

λΆ€λ™μ†Œμˆ˜μ μ΄λž€?

Exponential 기호λ₯Ό μ‚¬μš©ν•˜μ—¬ μ†Œμˆ˜μ  μœ„μΉ˜λ₯Ό μ‘°μ •ν•  수 μžˆλ‹€. 3.14λŠ” 0.314e1, 31.4e-1, 314e-2λ‘œλ„ ν‘œν˜„ν•  수 μžˆλŠ”λ°, 이처럼 μ†Œμˆ˜μ μ΄ λ‘₯λ‘₯ λ– λ‹€λ‹ˆλ©΄μ„œ 움직인닀고 ν•˜μ—¬μ„œ μ΄λ ‡κ²Œ ν‘œν˜„ν•˜λŠ” 방식을 λΆ€λ™μ†Œμˆ˜μ (floating point) 방식이라고 λΆ€λ₯Έλ‹€.

μ»΄ν“¨ν„°λŠ” 1κ³Ό 0으둜 데이터λ₯Ό μ €μž₯ν•œλ‹€. λ”°λΌμ„œ μ‹€μˆ˜ 값을 μ €μž₯ν•  λ•Œ λΆ€λ™μ†Œμˆ˜μ  λ°©μ‹μœΌλ‘œ μ €μž₯ν•˜λ €λ©΄ 1κ³Ό 0으둜 λ³€ν™˜ν•΄μ•Ό ν•œλ‹€. JavaλŠ” λΆ€λ™μ†Œμˆ˜μ μ„ μ €μž₯ν•  λ•Œ μ „κΈ°μ „μžκΈ°μˆ μžν˜‘νšŒ(IEEE)μ—μ„œ κ°œλ°œν•œ IEEE 754 λͺ…세에 따라 2μ§„μˆ˜λ‘œ λ³€ν™˜ν•œλ‹€.

λΆ€λ™μ†Œμˆ˜μ μ˜ μ΅œμ†Œκ°’κ³Ό μ΅œλŒ€κ°’

μžλ°”μ—μ„œ λΆ€λ™μ†Œμˆ˜μ  λ°μ΄ν„°νƒ€μž…μ˜ μ’…λ₯˜μ—λŠ” Floatκ³Ό Double이 μžˆλ‹€. Float 값은 4λ°”μ΄νŠΈμ— μ €μž₯되고, Double 값은 8λ°”μ΄νŠΈμ— μ €μž₯λœλ‹€.

μ΅œμ†Œκ°’κ³Ό μ΅œλŒ€κ°’ ν™•μΈν•˜κΈ°

.MAX_VALUE, .MIN_VALUEλ₯Ό μ‚¬μš©ν•˜μ—¬ μ΅œλŒ“κ°’κ³Ό μ΅œμ†Ÿκ°’μ„ 확인할 수 μžˆλ‹€.

1
2
3
4
5
6
7
// 4λ°”μ΄νŠΈ λΆ€λ™μ†Œμˆ˜μ μ˜ μ΅œλŒ€κ°’κ³Ό μ΅œμ†Œκ°’
System.out.println(Float.MAX_VALUE);    //3.4028235E38
System.out.println(Float.MIN_VALUE);    //1.4E-45

// 8λ°”μ΄νŠΈ λΆ€λ™μ†Œμˆ˜μ μ˜ μ΅œλŒ€κ°’κ³Ό μ΅œμ†Œκ°’
System.out.println(Float.MAX_VALUE);    //1.7976931348623157E308
System.out.println(Float.MIN_VALUE);    //4.9E-324

4λ°”μ΄νŠΈ λ©”λͺ¨λ¦¬λŠ” μ΅œλŒ€ 7자리 λΆ€λ™μ†Œμˆ˜μ μ„, 8λ°”μ΄νŠΈμ˜ λ©”λͺ¨λ¦¬λŠ” μ΅œλŒ€ 16자리의 λΆ€λ™μ†Œμˆ˜μ μ„ μ €μž₯ν•  수 μžˆλ‹€.

λ©”λͺ¨λ¦¬μ— 크기λ₯Ό λ„˜λŠ” κ°’ 좜λ ₯해보기

1
2
3
4
// 유효자릿수λ₯Ό 
// μ΄ˆκ³Όν•˜λŠ” 경우 반올림 μ²˜λ¦¬λ˜κ±°λ‚˜ μž˜λ¦°λ‹€.
System.out.println(9999999.4f);     //9999999.0
System.out.println(9.9999994f);     //9.999999
1
2
3
System.out.println(987654321.1234567f);
System.out.println(987654321123456.7f);
System.out.println(9.876543211234567f);
This post is licensed under CC BY 4.0 by the author.

🍡 μ΄μŠ€μΌ€μ΄ν”„ 문자(escape character)

🍡 λ¬Έμžμ—΄κ³Ό λ‹€λ₯Έ λ°μ΄ν„°νƒ€μž…μ˜ 값을 μ—°κ²°ν•˜κΈ°

Loading comments from Disqus ...