[php-src] Issue #8314: EXP(N) != M_E ** N
| From: | REGZ-PL | Date: | Thu, 07 Apr 2022 19:14:09 +0000 |
| Subject: | [php-src] Issue #8314: EXP(N) != M_E ** N | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-240770@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/8314
Comment Author: REGZ-PL
### Main problems
- **Incorrect previous assumptions**
We are in 2022 and new opportunities allow us to solve the problem of incorrect assumptions of the
precursors. Why adding the numbers 0.1 and 0.2 has to give 0.3**0000000000000004**? The child would
show that there is a mistake here. I understand that this is due to the way of storing data in the
device's memory. I created an example of solving this problem in the modern world where
``
0.1 + 0.2 = 0.3` not `0.30000000000000004` and
`2.71828182845904523536028747135266249775724709369995 +
2.71828182845904523536028747135266249775724709369995 =
5.43656365691809047072057494270532499551449418739990`` is calculated without any problem.
Excuse me for a bad programming style.
@cmb69 - https://3v4l.org/2eENj
- **Calculations are not standardized**
Correct me if I am wrong, but for these functions the results should be identical and
comparable.
Code:
```
<?PHP
FUNCTION EXP1(INT $N) : float { RETURN M_E ** $N; }
FUNCTION EXP2(INT $N) : float { RETURN pow(M_E, $N); }
FUNCTION EXP3(INT $N) : float { RETURN bcpow(M_E, $N, 16); }
var_dump(EXP(2));
var_dump(EXP1(2));
var_dump(EXP2(2));
var_dump(EXP3(2));
```
Output:
```
Output for 8.0.1 - 8.0.17, 8.1.0 - 8.1.4
float(7.38905609893065)
float(7.3890560989306495)
float(7.3890560989306495)
float(7.389056098930404)
Output for 7.4.0 - 7.4.28
float(7.3890560989307)
float(7.3890560989306)
float(7.3890560989306)
float(7.3890560989304)
```