File: test_float_builtins.c

package info (click to toggle)
emscripten 3.1.69%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 121,860 kB
  • sloc: ansic: 636,110; cpp: 425,974; javascript: 78,401; python: 58,404; sh: 49,154; pascal: 5,237; makefile: 3,366; asm: 2,415; lisp: 1,869
file content (72 lines) | stat: -rw-r--r-- 2,209 bytes parent folder | download | duplicates (2)
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
 * Copyright 2017 The Emscripten Authors.  All rights reserved.
 * Emscripten is available under two separate licenses, the MIT license and the
 * University of Illinois/NCSA Open Source License.  Both these licenses can be
 * found in the LICENSE file.
 */

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

// Prints the float/double/long double versions of the given function
// e.g.: TEST(fmax) prints fmaxf : fmax : fmaxl
#define TEST(func)                                                             \
  printf("__builtin_" #func " %f : %f : %Lf\n",                                \
         __builtin_##func##f(f1, f2),                                          \
         __builtin_##func(d1, d2),                                             \
         __builtin_##func##l(l1, l2));

#define TESTI(func)                                                            \
  printf("__builtin_" #func " %f : %f : %Lf\n",                                \
         __builtin_##func##f(f1, i1),                                          \
         __builtin_##func(d1, i1),                                             \
         __builtin_##func##l(l1, i1));

int test_builtins() {
  int i1 = 88;
  float f1 = 0.1234f;
  float f2 = 0.5678f;
  double d1 = 1.0101;
  double d2 = 0.10101;
  long double l1 = 12.0123L;
  long double l2 = 3.3201L;
  TEST(fmax)
  TEST(fmin)
  TEST(fmod)
  TEST(scalbn)
  TEST(ldexp)

  TEST(pow)
  TESTI(powi)
  return 0;
}

void test_exp_log(double x) {
  double a = exp2(x);
  double b = log10(x);
  float c = log10f(x);
  double d = acos(x);
  printf("%f : %f : %f : %d\n", a, b, c, isnan(d));
}

void test_long_double(long double x) {
  printf("sqrt(x) = %Lf\n", sqrtl(x));
  printf("ceil(x) = %Lf\n", ceill(x));
  printf("floor(x) = %Lf\n", floorl(x));
  printf("atan(x) = %Lf\n", atanl(x));
  printf("atan2(x,1) = %Lf\n", atan2l(x, 1));
  printf("asin(x) = %Lf\n", asinl(x));
  printf("acos(x) = %Lf\n", acosl(x));
  printf("expl(x) = %Lf\n", expl(x));
  printf("ldexpl(x) = %Lf\n", ldexpl(x, 7));
  printf("scalbnl(x) = %Lf\n", scalbnl(x, 2));
}

int main() {
  puts("***start***");
  test_builtins();
  test_exp_log(1234.5678);
  test_long_double(16);
  puts("***end***");
  return 0;
}