On Thu, Dec 2, 2010 at 8:20 PM, Matt Turner <matts...@gmail.com> wrote:
> On Wed, Dec 1, 2010 at 11:24 PM, Ian Romanick <i...@freedesktop.org> wrote:
>> On 12/01/2010 01:40 PM, Matt Turner wrote:
>>> 1/ln(2) is equivalent to log2(e), so define it as such.
>>>
>>> log2(e) = ln(e)/ln(2) = 1/ln(2)
>>>
>>> M_PI is updated to add some precision (value found in my math.h header).
>>
>> I wish I had noticed this when I added M_LOG2E.  It seems better to
>> replace the single use of ONE_DIV_LN2 (in prog_statevars.c) with M_LOG2E.
>
> I think replacing ONE_DIV_LN2 with M_LOG2E in its single use makes the
> code harder to understand, especially since the next line is
>
> value[2] = (GLfloat)(ctx->Fog.Density * ONE_DIV_LN2);
> value[3] = (GLfloat)(ctx->Fog.Density * ONE_DIV_SQRT_LN2);
>
> It's not intuitively obvious that M_LOG2E == 1/ln(2), so I actually
> think the patch is good as is.
>
> Matt

I never saw any response, so how about the two attached patches?

Matt
From 00e72b8eff5726517f623d9f61efa018fc41b1d8 Mon Sep 17 00:00:00 2001
From: Matt Turner <matts...@gmail.com>
Date: Wed, 4 May 2011 15:22:42 -0400
Subject: [PATCH 1/2] Replace ONE_DIV_LN2 constant with M_LOG2E

1/ln(2) is equivalent to log2(e), so define it as such.

log2(e) = ln(e)/ln(2) = 1/ln(2)

Signed-off-by: Matt Turner <matts...@gmail.com>
---
 src/mesa/main/compiler.h          |    4 ----
 src/mesa/program/prog_statevars.c |    2 +-
 2 files changed, 1 insertions(+), 5 deletions(-)

diff --git a/src/mesa/main/compiler.h b/src/mesa/main/compiler.h
index e17fd0f..81e08a0 100644
--- a/src/mesa/main/compiler.h
+++ b/src/mesa/main/compiler.h
@@ -366,10 +366,6 @@ static INLINE GLuint CPU_TO_LE32(GLuint x)
 #define M_LOG2E     (1.4426950408889634074)
 #endif
 
-#ifndef ONE_DIV_LN2
-#define ONE_DIV_LN2 (1.442695040888963456)
-#endif
-
 #ifndef ONE_DIV_SQRT_LN2
 #define ONE_DIV_SQRT_LN2 (1.201122408786449815)
 #endif
diff --git a/src/mesa/program/prog_statevars.c b/src/mesa/program/prog_statevars.c
index d94d7fe..16f9690 100644
--- a/src/mesa/program/prog_statevars.c
+++ b/src/mesa/program/prog_statevars.c
@@ -459,7 +459,7 @@ _mesa_fetch_state(struct gl_context *ctx, const gl_state_index state[],
          value[0] = (ctx->Fog.End == ctx->Fog.Start)
             ? 1.0f : (GLfloat)(-1.0F / (ctx->Fog.End - ctx->Fog.Start));
          value[1] = ctx->Fog.End * -value[0];
-         value[2] = (GLfloat)(ctx->Fog.Density * ONE_DIV_LN2);
+         value[2] = (GLfloat)(ctx->Fog.Density * M_LOG2E); /* M_LOG2E == 1/ln(2) */
          value[3] = (GLfloat)(ctx->Fog.Density * ONE_DIV_SQRT_LN2);
          return;
 
-- 
1.7.3.4

From dc6c6dd7f0f168c9233e637871d54f04f1fc7266 Mon Sep 17 00:00:00 2001
From: Matt Turner <matts...@gmail.com>
Date: Wed, 4 May 2011 15:23:43 -0400
Subject: [PATCH 2/2] Add precision to M_PI constant

Value found in my math.h header.

Signed-off-by: Matt Turner <matts...@gmail.com>
---
 src/mesa/main/compiler.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/src/mesa/main/compiler.h b/src/mesa/main/compiler.h
index 81e08a0..743841b 100644
--- a/src/mesa/main/compiler.h
+++ b/src/mesa/main/compiler.h
@@ -355,7 +355,7 @@ static INLINE GLuint CPU_TO_LE32(GLuint x)
 
 
 #ifndef M_PI
-#define M_PI (3.1415926536)
+#define M_PI (3.14159265358979323846)
 #endif
 
 #ifndef M_E
-- 
1.7.3.4

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to