summary refs log tree commit diff stats
path: root/tests/accept/run/tfloat2.nim
blob: b0df1e8b70e6cc4fd4d5bf22fe8a9058bc788f64 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
discard """
  file: "tfloat2.nim"
  outputsub: "Error: unhandled exception: FPU operation caused a NaN result [EFloatInvalidOp]"
"""
# Test new floating point exceptions

{.floatChecks: on.}

var x = 0.0
var y = 0.0

echo x / y #OUT Error: unhandled exception: FPU operation caused a NaN result [EFloatInvalidOp]
ol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
discard """
  file: "tfloat3.nim"
  output: "Nimrod    3.4368930843, 0.3299290698 C double: 3.4368930843, 0.3299290698"
"""

import math, strutils

{.emit: """
void printFloats(void) {
    double y = 1.234567890123456789;
    
    printf("C double: %.10f, %.10f ", exp(y), cos(y));
}
""".}

proc c_printf(frmt: CString) {.importc: "printf", header: "<stdio.h>", varargs.}
proc printFloats {.importc, nodecl.}

var x: float = 1.234567890123456789
c_printf("Nimrod    %.10f, %.10f ", exp(x), cos(x))
printFloats()