September 01, 2012
On Sat, Sep 1, 2012 at 3:46 AM, Rene Zwanenburg <renezwanenburg@gmail.com> wrote:

> Use caching for data which is really expensive to calculate. For relatively trivial stuff like sin(), just calculate it during runtime.

On a somewhat related note, I remember realizing a few years ago that it was faster to generate the first thousands of primes on the fly than to pre-generate them and read them from a file.
September 01, 2012
On Saturday, 1 September 2012 at 01:46:38 UTC, Rene Zwanenburg wrote:
> On Thursday, 30 August 2012 at 09:41:43 UTC, Danny Arends wrote:
>> I wrote a blog post about the stuff I've been doing last weekend using CTFE.
>> All comments are welcome, you can find the blog post at:
>>
>> http://www.dannyarends.nl/index.cgi?viewDetailed=00029
>>
>> Danny Arends
>> http://www.dannyarends.nl
>
> It's always good to see someone write about the unusual features of D, but I have a non-D related point of criticism regarding your post: lookup tables for trig functions are a thing from the nineties.

Thanks for reply! I see you got the point from the post :)

The stuff I implemented in CTFE is course many times worse then the std.math sine and cosine functions (they fall back to single operators in ASM)I could have just as well done:

pure T[2][] gen_trigonometric(){
  T[2][] result = new T[2][](360);
  foreach(i; 0 .. 360){
    result[i] = [sin(x), cos(x)];
  }
  return result;
}

But well then showing off D's feature to call (polymorphic) user functions in CTFE is then less clear :)

>
> I'm not trying to make some bad 'the nineties called' joke ;). Since at least a decade, calling the trig functions will usually be significantly faster in a real application than a lookup table. Simple benchmarks may show a performance improvement, but that's because the table still resides in the L1 cache. A real application will often have to read the table from main memory, which is orders of magnitude slower than simply doing the computation.
>
> Use caching for data which is really expensive to calculate. For relatively trivial stuff like sin(), just calculate it during runtime.

I don't try to advocating people start using look-up tables for sine and cosine. It's an example to show how cool I think CTFE is for stuff like this. I could have also taken the much more used example of CTFE calculating primes. However in that case (primes) it is not useful to have a user function doing it for
floats, doubles and reals. :-P

Gr,
Danny Arends
September 01, 2012
On Saturday, 1 September 2012 at 00:47:20 UTC, bearophile wrote:
> Danny Arends:
>
>> Another post: http://www.dannyarends.nl/?viewDetailed=00030
>
> pure mat!(T)[3][] gen_rotationmatrices(T = float)(){
>
> I suggest to write something like this (note the casing and other details):
>
> Mat!T[3][] genRotationMatrices(T = float)() pure {
>

Again many thanks for the feedback.
I'll fix this indeed :)

>
> tmp += mixin('A[i][k] '~op~' B[k][j]');
>
> This seems OK, but it looks a bit convoluted. Maybe something like this works (untested):
>
> tmp += A[i][k].opBinary!op(B[k][j]);
>
>

I'll test it, though I wanted to show off the mixin concept, I put a hyper link to the Dlang information page about mixins. So that people can read up on what they are.

>
> pure auto yaw(int deg){
>    deg = degreeloop(deg);
>    return cast(matrix)rmatrix[deg][YAW];
> }
>
> I suggest generally to try to avoid casts, where possible.
>

Do you have a suggestion to get around this cast ?

> Bye,
> bearophile

Gr,
Danny Arends
September 03, 2012
On 08/30/2012 02:41 AM, Danny Arends wrote:
> I wrote a blog post about the stuff I've been doing last weekend using
> CTFE.
> All comments are welcome, you can find the blog post at:
>
> http://www.dannyarends.nl/index.cgi?viewDetailed=00029
>
> Danny Arends
> http://www.dannyarends.nl

Thanks for the blog posts.

I wanted to mention that the community has been moving away from the D 1 and D 2 namings. D1 is being discontinued by the end of the year and D2 wants to be called simply D, like in the subject of this thread. ;)

Ali

September 04, 2012
On 8/30/12 11:41 AM, Danny Arends wrote:
> I wrote a blog post about the stuff I've been doing last weekend using
> CTFE.
> All comments are welcome, you can find the blog post at:
>
> http://www.dannyarends.nl/index.cgi?viewDetailed=00029

On reddit:

http://www.reddit.com/r/programming/comments/zcd19/using_ds_compiletime_evaluation_to_speed_up_sine/


Andrei

September 04, 2012
Thanks for redditting, also put the second blog post on there

http://redd.it/zcj4p

I'll update both blogs (due to previous comments )as soon as I get round 2 it.

On Tuesday, 4 September 2012 at 16:55:14 UTC, Andrei Alexandrescu wrote:
> On 8/30/12 11:41 AM, Danny Arends wrote:
>> I wrote a blog post about the stuff I've been doing last weekend using
>> CTFE.
>> All comments are welcome, you can find the blog post at:
>>
>> http://www.dannyarends.nl/index.cgi?viewDetailed=00029
>
> On reddit:
>
> http://www.reddit.com/r/programming/comments/zcd19/using_ds_compiletime_evaluation_to_speed_up_sine/
>
>
> Andrei

1 2
Next ›   Last »