Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ea6c7135 authored by Nick Desaulniers's avatar Nick Desaulniers
Browse files

[frameworks][native][libs]{math|ui} fix -Wimplicit-int-float-conversion



Some of the overloaded constructors accept templated types. This makes
it simple to specify Vec{2|3}/Quat's using integer literals. This could
result in precision loss for large integrals that aren't precisely
representable by IEEE 754 Single Precision floats.  If you're creating
such primitives from such large values, and getting imprecision...well,
you kind of asked for it.

Add explicit casts to silence the warning.

Bug: 139945549
Test: mm
Change-Id: Icaaa8906157aa166f54d915fca643efd639fdafa
Signed-off-by: default avatarNick Desaulniers <ndesaulniers@google.com>
parent 1ed80f45
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -109,7 +109,7 @@ public:


    // initialize from 4 values to w + xi + yj + zk
    // initialize from 4 values to w + xi + yj + zk
    template<typename A, typename B, typename C, typename D>
    template<typename A, typename B, typename C, typename D>
    constexpr TQuaternion(A w, B x, C y, D z) : x(x), y(y), z(z), w(w) { }
    constexpr TQuaternion(A w, B x, C y, D z) : x(static_cast<T>(x)), y(static_cast<T>(y)), z(static_cast<T>(z)), w(static_cast<T>(w)) { }


    // initialize from a vec3 + a value to : v.xi + v.yj + v.zk + w
    // initialize from a vec3 + a value to : v.xi + v.yj + v.zk + w
    template<typename A, typename B>
    template<typename A, typename B>
+1 −1
Original line number Original line Diff line number Diff line
@@ -89,7 +89,7 @@ public:
    constexpr TVec2(A v) : x(v), y(v) { }
    constexpr TVec2(A v) : x(v), y(v) { }


    template<typename A, typename B>
    template<typename A, typename B>
    constexpr TVec2(A x, B y) : x(x), y(y) { }
    constexpr TVec2(A x, B y) : x(static_cast<T>(x)), y(static_cast<T>(y)) { }


    template<typename A>
    template<typename A>
    explicit
    explicit
+3 −3
Original line number Original line Diff line number Diff line
@@ -86,13 +86,13 @@ public:


    // handles implicit conversion to a tvec4. must not be explicit.
    // handles implicit conversion to a tvec4. must not be explicit.
    template<typename A, typename = typename std::enable_if<std::is_arithmetic<A>::value >::type>
    template<typename A, typename = typename std::enable_if<std::is_arithmetic<A>::value >::type>
    constexpr TVec3(A v) : x(v), y(v), z(v) { }
    constexpr TVec3(A v) : x(static_cast<T>(v)), y(static_cast<T>(v)), z(static_cast<T>(v)) { }


    template<typename A, typename B, typename C>
    template<typename A, typename B, typename C>
    constexpr TVec3(A x, B y, C z) : x(x), y(y), z(z) { }
    constexpr TVec3(A x, B y, C z) : x(static_cast<T>(x)), y(static_cast<T>(y)), z(static_cast<T>(z)) { }


    template<typename A, typename B>
    template<typename A, typename B>
    constexpr TVec3(const TVec2<A>& v, B z) : x(v.x), y(v.y), z(z) { }
    constexpr TVec3(const TVec2<A>& v, B z) : x(v.x), y(v.y), z(static_cast<T>(z)) { }


    template<typename A>
    template<typename A>
    explicit
    explicit
+5 −1
Original line number Original line Diff line number Diff line
@@ -364,7 +364,11 @@ std::unique_ptr<float3[]> ColorSpace::createLUT(uint32_t size, const ColorSpace&
    for (uint32_t z = 0; z < size; z++) {
    for (uint32_t z = 0; z < size; z++) {
        for (int32_t y = int32_t(size - 1); y >= 0; y--) {
        for (int32_t y = int32_t(size - 1); y >= 0; y--) {
            for (uint32_t x = 0; x < size; x++) {
            for (uint32_t x = 0; x < size; x++) {
                *data++ = connector.transform({x * m, y * m, z * m});
                *data++ = connector.transform({
                    static_cast<float>(x) * m,
                    static_cast<float>(y) * m,
                    static_cast<float>(z) * m,
                });
            }
            }
        }
        }
    }
    }
+2 −2
Original line number Original line Diff line number Diff line
@@ -80,7 +80,7 @@ void GraphicBufferAllocator::dump(std::string& result) const {
        if (rec.size) {
        if (rec.size) {
            StringAppendF(&result,
            StringAppendF(&result,
                          "%10p: %7.2f KiB | %4u (%4u) x %4u | %4u | %8X | 0x%" PRIx64 " | %s\n",
                          "%10p: %7.2f KiB | %4u (%4u) x %4u | %4u | %8X | 0x%" PRIx64 " | %s\n",
                          list.keyAt(i), rec.size / 1024.0, rec.width, rec.stride, rec.height,
                          list.keyAt(i), static_cast<double>(rec.size) / 1024.0, rec.width, rec.stride, rec.height,
                          rec.layerCount, rec.format, rec.usage, rec.requestorName.c_str());
                          rec.layerCount, rec.format, rec.usage, rec.requestorName.c_str());
        } else {
        } else {
            StringAppendF(&result,
            StringAppendF(&result,
@@ -90,7 +90,7 @@ void GraphicBufferAllocator::dump(std::string& result) const {
        }
        }
        total += rec.size;
        total += rec.size;
    }
    }
    StringAppendF(&result, "Total allocated (estimate): %.2f KB\n", total / 1024.0);
    StringAppendF(&result, "Total allocated (estimate): %.2f KB\n", static_cast<double>(total) / 1024.0);


    result.append(mAllocator->dumpDebugInfo());
    result.append(mAllocator->dumpDebugInfo());
}
}
Loading