tfloat3.nim 476 B

12345678910111213141516171819202122
  1. discard """
  2. output: '''
  3. Nim 3.4368930843, 0.3299290698
  4. C double: 3.4368930843, 0.3299290698'''
  5. """
  6. import math, strutils
  7. {.emit: """
  8. void printFloats(void) {
  9. double y = 1.234567890123456789;
  10. printf("C double: %.10f, %.10f\n", exp(y), cos(y));
  11. }
  12. """.}
  13. proc c_printf(frmt: cstring) {.importc: "printf", header: "<stdio.h>", varargs.}
  14. proc printFloats {.importc, nodecl.}
  15. var x: float = 1.234567890123456789
  16. c_printf("Nim %.10f, %.10f\n", exp(x), cos(x))
  17. printFloats()