[Mesa-dev] [PATCH] Improve ONE_DIV_LN2 and M_PI constants

Matt Turner mattst88 at gmail.com
Wed May 4 12:25:15 PDT 2011


On Thu, Dec 2, 2010 at 8:20 PM, Matt Turner <mattst88 at gmail.com> wrote:
> On Wed, Dec 1, 2010 at 11:24 PM, Ian Romanick <idr at 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Replace-ONE_DIV_LN2-constant-with-M_LOG2E.patch
Type: text/x-patch
Size: 1640 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20110504/d05ea9a7/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-Add-precision-to-M_PI-constant.patch
Type: text/x-patch
Size: 714 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20110504/d05ea9a7/attachment-0001.bin>


More information about the mesa-dev mailing list