Skip to content

Wrong square root computation #173

@guidovranken

Description

@guidovranken
#include <relic_conf.h>
#include <relic.h>

int main(void)
{
    if ( core_init() != RLC_OK ) abort();

    bn_t A, R;

    bn_null(A); bn_new(A);
    bn_null(R); bn_new(R);

    //const char* s = "16";
    const char* s = "64";
    /* noret */ bn_read_str(A, s, strlen(s), 10);

    /* noret */ bn_srt(R, A);

    int outsize = bn_size_str(R, 10);
    char* s2 = malloc(outsize);
    /* noret */ bn_write_str(s2, outsize, R, 10);
    printf("%s\n", s2);
    free(s2);

    bn_free(A);
    bn_free(R);
    return 0;
}

It says the square root of 16 is 5, and the square root of 64 is 9. Is this a bug or an internal rounding effect that's deemed acceptable?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions