File: test_float16.ml

package info (click to toggle)
js-of-ocaml 6.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 37,932 kB
  • sloc: ml: 135,957; javascript: 58,364; ansic: 437; makefile: 422; sh: 12; perl: 4
file content (24 lines) | stat: -rw-r--r-- 594 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
let max = (1 lsl 16) - 1

let ba =
  Bigarray.Array1.init Bigarray.int16_unsigned Bigarray.c_layout (max + 1) (fun x -> x)

let s = Marshal.to_string ba []

let b = Bytes.of_string s

let s =
  Bytes.to_string
    (Bytes.set b 50 '\r';
     b)

let ba' : (float, Bigarray.float16_elt, Bigarray.c_layout) Bigarray.Array1.t =
  Marshal.from_string s 0

let () =
  for i = 0 to max do
    let old = ba'.{i} in
    Printf.printf "%h\n%!" (if Float.is_nan old then Float.nan else old);
    ba'.{i} <- old;
    if old = old && not (old = ba'.{i}) then Printf.printf "%g <> %g\n%!" old ba'.{i}
  done