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

// Test for regression of a bug we had were mul and div could clobber
// derivatives if the result went to the operand itself (like x=x*x).
//
// When the bug was present, x and gx would not have matching derivs!
//

shader test()
{
    float x = u;

    float gx = x * x;
    x = x* x;
    printf ("mul:\n");
    printf ("  x  = %g, dx=%g dy=%g\n", x, Dx(x), Dy(x));
    printf ("  gx = %g, dx=%g dy=%g\n", gx, Dx(gx), Dy(gx));

    float y = u;
    float gy = y / y;
    y = y / y;
    printf ("div:\n");
    printf ("  y  = %g, dx=%g dy=%g\n", y, Dx(y), Dy(y));
    printf ("  gy = %g, dx=%g dy=%g\n", gy, Dx(gy), Dy(gy));
}
