php 에서 double 처리방법이 없는게 맞나요?

cococo의 이미지

doubleval() 찾아보니까 floatval() 의 alise 라고 써 있네요. 이게 무쉰...
스텍오버플러우 뒤져봐도 없다 그러고....

자릿수 계산이 엄밀하게 필요한 코드인데, float 로 쓰려니 불안하기 짝이 없습니다.
혹시 php 에서 double 필요하신 분들은 어떻게 처리하시나요?

비슷한 상황 겪어보신 분들은 의견 주시면 감사하겠습니다.

이상입니다. 즐거운 하루 되시기 바랍니다.

익명 사용자의 이미지

http://php.net/manual/en/language.types.float.php

Quote:
Floating point numbers have limited precision. Although it depends on the system, PHP typically uses the IEEE 754 double precision format, which will give a maximum relative error due to rounding in the order of 1.11e-16.

시스템에 따라 다르기는 하지만 보통은 배정밀도 부동소수점 포맷을 쓴다고 하네요.

문제는 "자릿수 계산"이 어디까지 "엄밀"해야 하느냐입니다. 단정밀도가 불충분하다면 배정밀도로는 충분한가요?

해당 링크에 대안이 소개되어 있군요.

Quote:
If higher precision is necessary, the arbitrary precision math functions and gmp functions are available.

경우에 따라서는 유리수 클래스(numerator/denominator 꼴)나 fixed-point 산술을 구현하는 게 더 적합할 때도 있습니다.