test.c 1.21 KB
/* -----------------------------------------------------------------------------
 *  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 <my_printf.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;
  }