Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Result of ac_ieee_float32 addition has wrong sign if AC_RND_INF rounding mode is used #14

Open
xovano opened this issue Sep 10, 2020 · 3 comments

Comments

@xovano
Copy link

xovano commented Sep 10, 2020

ac_ieee32_float32::add returns a result with wrong sign for some combinations of operand values if AC_RND_INF rounding mode is used. The following program

#include "ac_std_float.h"
#include <cstdint>
#include <cstring>
#include <iomanip>
#include <iostream>

int main() {
    std::uint32_t au = 0x380470edu;
    std::uint32_t bu = 0x447fffffu;

    float af, bf;
    std::memcpy(&af, &au, sizeof af);
    std::memcpy(&bf, &bu, sizeof bf);

    ac_ieee_float32 a = af;
    ac_ieee_float32 b = bf;
    ac_ieee_float32 c = a.add<AC_RND_INF, false>(b);

    std::cout << std::setprecision(9) << a << " + " << b << " = " << c << std::endl;
}

prints

3.15764228e-05 + 1023.99994 = -1024

which is obviously wrong. It seems that the code that determines sign of result has bug.

Compilers used: MinGW-w64 GCC 8.0.1 x86_64 and MSVC 2019 (v16.7.2).

@miklhh
Copy link

miklhh commented Apr 13, 2021

Has this been addressed yet?

@andres-takach
Copy link
Collaborator

Yes it was addressed in version v4.1.0. The mention of the fix was missed in the release notes.

@miklhh
Copy link

miklhh commented Apr 15, 2021

Yes it was addressed in version v4.1.0. The mention of the fix was missed in the release notes.

Thank you Andres.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants