성태의 닷넷 이야기
홈 주인
모아 놓은 자료
프로그래밍
질문/답변
사용자 관리
사용자
메뉴
아티클
외부 아티클
유용한 코드
온라인 기능
MathJax 입력기
최근 덧글
[정성태] 그냥 RSS Reader 기능과 약간의 UI 편의성 때문에 사용...
[이종효] 오래된 소프트웨어는 보안 위협이 되기도 합니다. 혹시 어떤 기능...
[정성태] @Keystroke IEEE의 문서를 소개해 주시다니... +_...
[손민수 (Keystroke)] 괜히 듀얼채널 구성할 때 한번에 같은 제품 사라고 하는 것이 아...
[정성태] 전각(Full-width)/반각(Half-width) 기능을 토...
[정성태] Vector에 대한 내용은 없습니다. Vector가 닷넷 BCL...
[orion] 글 읽고 찾아보니 디자인 타임에는 InitializeCompon...
[orion] 연휴 전에 재현 프로젝트 올리자 생각해 놓고 여의치 않아서 못 ...
[정성태] 아래의 글에 정리했으니 참고하세요. C# - Typed D...
[정성태] 간단한 재현 프로젝트라도 있을까요? 저런 식으로 설명만 해...
글쓰기
제목
이름
암호
전자우편
HTML
홈페이지
유형
제니퍼 .NET
닷넷
COM 개체 관련
스크립트
VC++
VS.NET IDE
Windows
Team Foundation Server
디버깅 기술
오류 유형
개발 환경 구성
웹
기타
Linux
Java
DDK
Math
Phone
Graphics
사물인터넷
부모글 보이기/감추기
내용
<div style='display: inline'> <h1 style='font-family: Malgun Gothic, Consolas; font-size: 20pt; color: #006699; text-align: center; font-weight: bold'>C# 컴파일 옵션 - Check for arithmetic overflow/underflow</h1> <p> 아래의 글 덕분에 처음으로 overflow/underflow에 대해 심각하게 생각해 보았습니다. ^^<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > 오버플로우와 언더플로우 ; <a target='tab' href='http://www.sysnet.pe.kr/3/0/5019'>http://www.sysnet.pe.kr/3/0/5019</a> </pre> <br /> 위의 의견에 따르면, (예를 들어) MaxValue + 1일 때의 상황이 overflow라고 불리기도 하지만 (예를 들어) MinValue - 1일 때의 상황 역시 overflow입니다. 실제로 wiki 정의에서도 이것을 찾아볼 수 있습니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > Integer overflow ; <a target='tab' href='https://en.wikipedia.org/wiki/Integer_overflow'>https://en.wikipedia.org/wiki/Integer_overflow</a> </pre> <br /> <div style='BACKGROUND-COLOR: #ccffcc; padding: 10px 10px 5px 10px; MARGIN: 0px 10px 10px 10px; FONT-FAMILY: Malgun Gothic, Consolas, Verdana; COLOR: #005555'> In computer programming, an <span style='color: blue; font-weight: bold'>integer overflow occurs</span> when an arithmetic operation attempts to create a numeric value that is outside of the range that can be represented with a given number of bits -<span style='color: blue; font-weight: bold'> either larger than the maximum or lower than the minimum representable value.</span> </div><br /> <br /> 그리고 옵션 명에도 나오지만 특히나 "arithmetic <span style='color: blue; font-weight: bold'>underflow</span>"는, <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > Arithmetic underflow ; <a target='tab' href='https://en.wikipedia.org/wiki/Arithmetic_underflow'>https://en.wikipedia.org/wiki/Arithmetic_underflow</a> </pre> <br /> <div style='BACKGROUND-COLOR: #ccffcc; padding: 10px 10px 5px 10px; MARGIN: 0px 10px 10px 10px; FONT-FAMILY: Malgun Gothic, Consolas, Verdana; COLOR: #005555'> The term arithmetic underflow (or "floating point underflow", or just "underflow") is a condition in a computer program where the result of a calculation is a number of smaller absolute value than the computer can actually represent in memory on its CPU. <br /> <br /> <span style='color: blue; font-weight: bold'>Arithmetic underflow can occur when the true result of a floating point operation is smaller in magnitude (that is, closer to zero) than the smallest value representable as a normal floating point number in the target datatype.[1] Underflow can in part be regarded as negative overflow of the exponent of the floating point value.</span> For example, if the exponent part can represent values from ?128 to 127, then a result with a value less than ?128 may cause underflow. </div><br /> <br /> 이렇게 부동 소수점에서 (0인 듯 0이 아닌 0 같을 정도로) 0에 가까운 값이지만 정밀도로 표현할 수 없어 그냥 0으로 설정해 버리는 경우를 의미합니다.<br /> <br /> <hr style='width: 50%' /><br /> <br /> 이건 그냥 제 생각이지만, 해당 옵션의 문자열을 지정한 마이크로소프트 측의 개발자는 여기서의 underflow를 "integer underflow"로 여겼을 가능성이 크고, 아래의 링크에서와 같이 많은 글들이 (암묵적으로) MinValue보다 값이 낮아졌을 때의 상황을 의미하는 단어로 쓴 것 같습니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > CWE-191: Integer Underflow (Wrap or Wraparound) ; <a target='tab' href='https://cwe.mitre.org/data/definitions/191.html'>https://cwe.mitre.org/data/definitions/191.html</a> Java SE 8's New Compact Profiles and Integer APIs ; <a target='tab' href='http://www.informit.com/articles/article.aspx?p=2216988'>http://www.informit.com/articles/article.aspx?p=2216988</a> Overflow And Underflow of Data Types in Java ; <a target='tab' href='https://dzone.com/articles/overflow-and-underflow-dat'>https://dzone.com/articles/overflow-and-underflow-dat</a> Integer Overflow/Underflow and Floating Point Imprecision. ; <a target='tab' href='https://medium.com/@taabishm2/integer-overflow-underflow-and-floating-point-imprecision-6ba869a99033'>https://medium.com/@taabishm2/integer-overflow-underflow-and-floating-point-imprecision-6ba869a99033</a> Integer underflow ; <a target='tab' href='https://scc.ustc.edu.cn/zlsc/sugon/intel/ssadiag_docs/pt_reference/references/sc_int_underflow.htm'>https://scc.ustc.edu.cn/zlsc/sugon/intel/ssadiag_docs/pt_reference/references/sc_int_underflow.htm</a> </pre> <br /> 재미있는 것은, MSIL 코드를 보면 빼기(Subtract) 연산에서 overflow라는 의미의 "Ovf" 접두사를 넣었다는 것입니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > OpCodes.Sub_Ovf 필드 ; <a target='tab' href='https://docs.microsoft.com/en-us/dotnet/api/system.reflection.emit.opcodes.sub_ovf'>https://docs.microsoft.com/en-us/dotnet/api/system.reflection.emit.opcodes.sub_ovf</a> </pre> <br /> IL 코드 설계자가 <a target='tab' href='https://docs.microsoft.com/en-us/dotnet/api/system.reflection.emit.opcodes.add_ovf'>Add_Ovf</a>와 함께 빼기에서도 (Sub_Udf가 아닌) Sub_Ovf를 사용했다는 것은 overflow의 엄밀한 의미를 알고 지킨 것 같습니다.<br /> <br /> 또한, "<a target='tab' href='https://docs.microsoft.com/en-us/dotnet/api/system.reflection.emit.opcodes.sub_ovf'>OpCodes.Sub_Ovf 필드</a>" 도움말 내용을 보면,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > This operation is performed on signed integers; for floating-point values, use <a target='tab' href='https://docs.microsoft.com/en-us/dotnet/api/system.reflection.emit.opcodes.sub'>Sub</a>. </pre> <br /> 부동 소수점에 대해서는 ovf 성격의 연산을 지원하지 않고 정수형에 대해서만 지원합니다. 그리고 Sub 명령어의 도움말을 보면,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > Floating-point overflow returns +inf (PositiveInfinity) or -inf (NegativeInfinity). </pre> <br /> 부동 소수점의 경우 overflow 예외를 발생시키지 않는다고 나오며 underflow는 언급조차 안 하고 있습니다. <br /> <br /> 즉, .NET에서는 부동 소수점에서의 overflow/underflow에 대한 예외는 발생하지 않습니다. 실제로 "Check for arithmetic overflow/underflow" 옵션을 켜고 부동 소수점 빼기/나누기 등을 해보면, 단순하게 <a target='tab' href='https://docs.microsoft.com/en-us/dotnet/api/system.reflection.emit.opcodes.sub'>sub</a>, <a target='tab' href='https://docs.microsoft.com/en-us/dotnet/api/system.reflection.emit.opcodes.div'>div</a> IL 명령어로만 대체될 뿐 ovf 의미의 IL 코드가 사용되지 않습니다.<br /> <br /> <hr style='width: 50%' /><br /> <br /> 종합해 봤을 때, 프로젝트 속성 창의 "Check for arithmetic overflow/underflow"에서의 underflow 의미는 (MinValue - 1 상황에서 발생하는) "integer underflow"를 의미하는 것 같습니다. 일단, 이에 대해서는 다음의 이슈를 통해 마이크로소프트에 문의를 해두었으니,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > Is "Check for arithmetic overflow/underflow" option name valid? #3792 ; <a target='tab' href='https://github.com/dotnet/project-system/issues/3792'>https://github.com/dotnet/project-system/issues/3792</a> </pre> <br /> 추이를 지켜보고 향후 진도를 나가는 것이 좋겠다는 판단입니다.<br /> </p><br /> <br /><hr /><span style='color: Maroon'>[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]</span> </div>
첨부파일
스팸 방지용 인증 번호
1775
(왼쪽의 숫자를 입력해야 합니다.)