// Copyright Contributors to the Open Shading Language project.
// SPDX-License-Identifier: BSD-3-Clause
// https://github.com/AcademySoftwareFoundation/OpenShadingLanguage

shader
test ()
{
    {
        float a = M_E;
        float b = 27.0;
        printf ("  log (%g) = %g\n", a, log(a));
        printf ("  log (%g, %g) = %g\n", a, b, log(a,b));
        printf ("  log2 (%g) = %g\n", a, log2(a));
        printf ("  log10 (%g) = %g\n", a, log10(a));
        printf ("  logb (%g) = %g\n", a, logb(a));
        printf ("  exp (%g) = %g\n", a, exp(a));
        printf ("  exp2 (%g) = %g\n", a, exp2(a));
        printf ("  expm1 (%g) = %g\n", a, expm1(a));
        printf ("  erf (%g) = %g\n", a, erf(a));
        printf ("  erfc (%g) = %g\n", a, erfc(a));
        a = 10.0*M_E;
        printf ("  log (%g) = %g\n", a, log(a));
        printf ("  log (%g, %g) = %g\n", a, b, log(a,b));
        printf ("  log2 (%g) = %g\n", a, log2(a));
        printf ("  log10 (%g) = %g\n", a, log10(a));
        printf ("  logb (%g) = %g\n", a, logb(a));
        printf ("  exp (%g) = %g\n", a, exp(a));
        printf ("  exp2 (%g) = %g\n", a, exp2(a));
        printf ("  expm1 (%g) = %g\n", a, expm1(a));
        printf ("  erf (%g) = %g\n", a, erf(a));
        printf ("  erfc (%g) = %g\n", a, erfc(a));
        b = 2.0;
        a = 2.0;
        printf ("  log (%g, %g) = %g\n", a, b, log(a,b));
        b = 10.0;
        a = 10.0;
        printf ("  log (%g, %g) = %g\n", a, b, log(a,b));
        a = 2.0;
        b = 1.5;
        printf ("  pow (%g, %g) = %g\n", a, b, pow(a,b));
        a = -2.0;
        b = 1.5;
        printf ("  pow (%g, %g) = %g\n", a, b, pow(a,b));
        b = 0.0;
        printf ("  pow (%g, %g) = %g\n", a, b, pow(a,b));
        b = 3.0;
        printf ("  pow (%g, %g) = %g\n", a, b, pow(a,b));
        // catch some weird corner cases
        a = 0.0;
        printf ("  pow (%g, %g) = %g\n", a, b, pow(a,b));
        b = -3.0;
        printf ("  pow (%g, %g) = %g\n", a, b, pow(a,b));
        b = 0.0;
        printf ("  pow (%g, %g) = %g\n", a, b, pow(a,b));
        a = 2.2;
        b = 2;
        printf ("  pow (%g, %g) = %g\n", a, b, pow(a,b));
        a = -2.2;
        printf ("  pow (%g, %g) = %g\n", a, b, pow(a,b));
        a = 1e20;
        printf ("  pow (%g, %g) = %g     [should be clamped, not inf!]\n",
                a, b, pow(a,b));
        a = 2.5;
        b = 1.0;
        printf ("  pow (%g, %g) = %g\n", a, b, pow(a,b));
    }

    { 
        vector a = M_E;
        float b = 27.0;
        printf ("  log (%g) = %g\n", a, log(a));
        printf ("  log (%g, %g) = %g\n", a, b, log(a,b));
        printf ("  log2 (%g) = %g\n", a, log2(a));
        printf ("  log10 (%g) = %g\n", a, log10(a));
        printf ("  logb (%g) = %g\n", a, logb(a));
        printf ("  exp (%g) = %g\n", a, exp(a));
        printf ("  exp2 (%g) = %g\n", a, exp2(a));
        printf ("  expm1 (%g) = %g\n", a, expm1(a));
        a = 10.0*M_E;
        printf ("  log (%g) = %g\n", a, log(a));
        printf ("  log (%g, %g) = %g\n", a, b, log(a,b));
        printf ("  log2 (%g) = %g\n", a, log2(a));
        printf ("  log10 (%g) = %g\n", a, log10(a));
        printf ("  logb (%g) = %g\n", a, logb(a));
        printf ("  exp (%g) = %g\n", a, exp(a));
        printf ("  exp2 (%g) = %g\n", a, exp2(a));
        printf ("  expm1 (%g) = %g\n", a, expm1(a));
        a = 2.0;
        b = 2.0;
        printf ("  log (%g, %g) = %g\n", a, b, log(a,b));
        a = 10.0;
        b = 10.0;
        printf ("  log (%g, %g) = %g\n", a, b, log(a,b));
        a = 2.0;
        b = 1.5;
        printf ("  pow (%g, %g) = %g\n", a, b, pow(a,b));
        a = -2.0;
        b = 1.5;
        printf ("  pow (%g, %g) = %g\n", a, b, pow(a,b));
        b = 0.0;
        printf ("  pow (%g, %g) = %g\n", a, b, pow(a,b));
        b = 3.0;
        printf ("  pow (%g, %g) = %g\n", a, b, pow(a,b));
        // catch some weird corner cases
        a = 0.0;
        printf ("  pow (%g, %g) = %g\n", a, b, pow(a,b));
        b = -3.0;
        printf ("  pow (%g, %g) = %g\n", a, b, pow(a,b));
        b = 0.0;
        printf ("  pow (%g, %g) = %g\n", a, b, pow(a,b));
    }

    {
        // test triple vs triple
        vector a = 2.0;
        vector b = 1.5;
        printf ("  pow (%g, %g) = %g\n", a, b, pow(a,b));
        a = -2.0;
        b = 1.5;
        printf ("  pow (%g, %g) = %g\n", a, b, pow(a,b));
        b = 0.0;
        printf ("  pow (%g, %g) = %g\n", a, b, pow(a,b));
        b = 3.0;
        printf ("  pow (%g, %g) = %g\n", a, b, pow(a,b));
        // catch some weird corner cases
        a = 0.0;
        printf ("  pow (%g, %g) = %g\n", a, b, pow(a,b));
        b = -3.0;
        printf ("  pow (%g, %g) = %g\n", a, b, pow(a,b));
        b = 0.0;
        printf ("  pow (%g, %g) = %g\n", a, b, pow(a,b));
    }
}
