File: jsmath.cpp

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 (41 lines) | stat: -rw-r--r-- 1,060 bytes parent folder | download | duplicates (4)
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
#include <emscripten.h>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>

// Get values through a call to JS, so the optimizer can't hardcode results.
EM_JS(double, get_number, (), {
  return 2.1828;
});

EM_JS(double, get_another_number, (), {
  return 3.1415;
});

int main() {
  #define TEST_1_TRIPLE(name) \
    printf("float       %s => %f\n", #name, name##f((float)get_number())); \
    printf("double      %s => %f\n", #name, name(get_number()));

  #define TEST_2_TRIPLE(name) \
    printf("float       %s => %f\n", #name, name##f((float)get_number(), get_another_number())); \
    printf("double      %s => %f\n", #name, name(get_number(), get_another_number()));

  TEST_1_TRIPLE(cos)
  TEST_1_TRIPLE(sin)
  TEST_1_TRIPLE(tan)
  TEST_1_TRIPLE(acos)
  TEST_1_TRIPLE(asin)
  TEST_1_TRIPLE(atan)
  TEST_2_TRIPLE(atan2)
  TEST_1_TRIPLE(exp)
  TEST_1_TRIPLE(log)
  TEST_1_TRIPLE(sqrt)
  TEST_1_TRIPLE(fabs)
  TEST_1_TRIPLE(ceil)
  TEST_1_TRIPLE(floor)
  TEST_2_TRIPLE(pow)
  TEST_1_TRIPLE(round)
  TEST_1_TRIPLE(rint)
  TEST_1_TRIPLE(nearbyint)
}