File: float.ml

package info (click to toggle)
ocaml-decimal 1.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,028 kB
  • sloc: ml: 2,069; makefile: 16
file content (37 lines) | stat: -rw-r--r-- 1,115 bytes parent folder | download
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
open Alcotest
module Float = Stdlib.Float

let decimal = (module Decimal : TESTABLE with type t = Decimal.t)
let of_float = (Decimal.of_float [@alert "-lossy"])

let tests =
  [ ( "of_float",
      [ test_case "integral" `Quick
          begin
            fun () ->
              100. |> of_float |> check decimal "100" (Decimal.of_int 100)
          end;
        test_case "nan" `Quick
          begin
            fun () ->
              Float.nan |> of_float |> Decimal.is_nan |> check bool "NaN" true
          end;
        test_case "pos infinity" `Quick
          begin
            fun () ->
              Float.infinity
              |> of_float
              |> check decimal "+Infinity" Decimal.infinity
          end;
        test_case "neg infinity" `Quick
          begin
            fun () ->
              Float.neg_infinity
              |> of_float
              |> check decimal "-Infinity" Decimal.neg_infinity
          end;
        test_case "neg 0" `Quick
          begin
            fun () ->
              -0. |> of_float |> check decimal "-0.0" (Decimal.of_string "-0.0")
          end ] ) ]