Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use CX_LIMITED_RANGE ON/OFF

Tags:

c

pragma

In my test code, the cpu time used by complex computing between CX_LIMITED_RANGE ON/OFF has no differences. What's the difference between CX_LIMITED_RANGE ON/OFF, when and how we use the #pragma STDC CX_LIMITED_RANGE ON, and when we use default #pragma STDC CX_LIMITED_RANGE OFF.

Thanks!

void use_CX_LIMITED_RANGE()
{
    double complex z1 = 3.0 + I * 4.0;
    double complex z2 = 1.0 + I * 2.0;

#pragma STDC CX_LIMITED_RANGE ON

    clock_t c1 = clock();
        double complex z3;
        for (int i = 0; i < 100000; ++i) {
            z3 = cabs(z1 * z2); 
        }
        clock_t c2 = clock();
        printf("CX_LIMITED_RANGE ON %lu cpu clock\n", c2 - c1);
        printf("|z1 * z2| = %f + %fi\n", creal(z3), cimag(z3));

        printf("\n");

    #pragma STDC CX_LIMITED_RANGE OFF

        c1 = clock();
        for (int i = 0; i < 100000; ++i) {
            z3 = cabs(z1 * z2); 
        }
        c2 = clock();
        printf("CX_LIMITED_RANGE OFF %lu\n", c2 - c1);
        printf("|z1 * z2| = %f + %fi\n", creal(z3), cimag(z3));
    }
like image 836
user1462652 Avatar asked Sep 04 '25 17:09

user1462652


1 Answers

've been trying to use this pragma with GCC in C++, with no luck. I get 5x performance boost with -fcx-limited-range, but specifying that in the code instead has no effect. According to GCC's C99 status page, they don't support standard pragmas yet.

http://gcc.gnu.org/c99status.html

like image 182
Tronic Avatar answered Sep 07 '25 08:09

Tronic