File: jsmath.cpp

package info (click to toggle)
emscripten 2.0.12~dfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 108,440 kB
  • sloc: ansic: 510,324; cpp: 384,763; javascript: 84,341; python: 51,362; sh: 50,019; pascal: 4,159; makefile: 3,409; asm: 2,150; lisp: 1,869; ruby: 488; cs: 142
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)
}