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

Semantics of trunc, round and ceil #18

Open
emilaxelsson opened this issue Nov 5, 2012 · 0 comments
Open

Semantics of trunc, round and ceil #18

emilaxelsson opened this issue Nov 5, 2012 · 0 comments
Labels

Comments

@emilaxelsson
Copy link
Member

From the old trac:

The C functions trunc, round and ceil return 0 if the following conditions are satisfied:

  • their parameter is less than -32768 or greater than 32767
  • we want to store the result in a variable of type int8_t

Tested on: Fedora 15 x86
gcc (GCC) 4.6.0 20110530 (Red Hat 4.6.0-9)
Command line: gcc -W -Wall test.c -std=c99 -lm

A small test program:

#include <inttypes.h>
#include <stdio.h>
#include <math.h>

int main()
{
    float f = -33000.5;
    float origf = f;
    int8_t n;
    for (int i=0;i<1000;i++)
    {
        n = round(f);
        if (n==0)
            printf("%0.2f: %hd --- ", f, n);
        f += 1.0;
    }
    printf("\n");

    n = round(origf);
    printf("round(origf)=%hd, origf=%f\n", n, origf);
    n = round(-33000.5l);
    printf("round(-33000.5)=%hd\n", n);
    return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant