about summary refs log tree commit diff stats
path: root/tests/test12.c
blob: abb94c063163ed513c44552bbc1a994434e20c42 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <stdio.h>
#include <stdint.h>
#include <math.h>

typedef uint32_t    uint32;
typedef uint32      angle_t;

int main(int argc, char **argv)
{
    int64_t i64 = 1000000000000;
    double d = i64;
    printf("%lli => %f\n", i64, d);
    i64 = -i64;
    d = i64;
    printf("%lli => %f\n", i64, d);

    d = M_PI/4.0;
    d = d*(1<<30)/M_PI;
    angle_t u32 = (angle_t)d;
    printf("(angle_t)%f = %u == 0x%08X\n", d, u32, u32);

    int16_t a=0, b=0;

    #ifdef __ANDROID__
    asm volatile (
        "fldpi   \n"
        "fisttpl %0   \n"
    : "=m" (a));
    asm volatile (
        "fldpi      \n"
        "fchs       \n"
        "fistpl %0   \n"
    : "=m" (b));
    #else
    asm volatile (
        "fldpi   \n"
        "fisttp %0   \n"
    : "=m" (a));
    asm volatile (
        "fldpi      \n"
        "fchs       \n"
        "fistp %0   \n"
    : "=m" (b));
    #endif

    printf("go PI trucated=%d, -PI rounded=%d\n", a, b);

    return 0;
}