[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Tinycc-devel] Major bug in the pow function resulting in: 0.993013
From: |
Vincent Lefevre |
Subject: |
Re: [Tinycc-devel] Major bug in the pow function resulting in: 0.993013 = 0.860892 |
Date: |
Sat, 6 Jan 2024 00:56:00 +0100 |
User-agent: |
Mutt/2.2.12+67 (757ca3b3) vl-149028 (2023-09-09) |
Hi,
On 2024-01-05 13:47:25 +0100, Aurélie Tisson (BastaPrint) wrote:
> The same calculation gives me 2 different values : 0.993013 0.860892
> wheras it should give 0.993013 only (tells GCC).
Well, your code is not portable.
> #include <stdio.h>
> #include <math.h>
> int main(){
> double s = .7;
> double a = (1. - .1 * s) / (1. + .1 * s);
^^^^^^^^^^^ ^^^^^^^^^^^
> double b = pow(a, .05);
> double c = pow( ((1. - .1 * s) / (1. + .1 * s)), .05);
^^^^^^^^^^^ ^^^^^^^^^^^
> printf("%f %f \n", b, c);
> }
You should not depend on contraction of FP expressions.
Here, GCC may generate a FMA, which generally increases
the accuracy of the results.
--
Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)