test.c
1.21 KB
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
50
51
/* -----------------------------------------------------------------------------
* Copyright (C) 2019-2021 daiteq s.r.o. http://www.daiteq.com
*
* This program is distributed WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE.
*
* -----------------------------------------------------------------------------
* Filename : testhalf.c
* Authors : Roman Bartosinski
* Description : Simple test with packed half-precision ops
* Release :
* Version : 1.0
* Date : 27.4.2021
* -----------------------------------------------------------------------------
*/
#include <stdint.h>
#include <stdio.h>
half add(half a, half b)
{
return a+b;
}
half hsqrt(half a)
{
return a*a;
}
int main(void)
{
half a = 3.1415H;
half b = 2.71828H;
volatile half c;
printf("A=%f (x%04X)\n", a, *((uint16_t *)&a));
printf("B=%f (x%04X)\n", b, *((uint16_t *)&b));
c = add(a,b);
printf("a+b=%f (x%04X)\n", c, *((uint16_t *)&c));
printf("a-b=%f\n", a-b);
printf("b-a=%f\n", b-a);
c = hsqrt(a);
printf("A*A=%f (x%04X)\n", c, *((uint16_t *)&c));
return 0;
}