tstatic_with_converter.nim 718 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. discard """
  2. output: '''
  3. 9.0
  4. '''
  5. """
  6. ### bug #6773
  7. {.emit: """ /*INCLUDESECTION*/
  8. typedef double cimported;
  9. cimported set1_imported(double x) {
  10. return x;
  11. }
  12. """}
  13. type vfloat{.importc: "cimported".} = object
  14. proc set1(a: float): vfloat {.importc: "set1_imported".}
  15. converter scalar_to_vector(x: float): vfloat =
  16. set1(x)
  17. proc sqrt(x: vfloat): vfloat =
  18. x
  19. proc pow(x, y: vfloat): vfloat =
  20. y
  21. proc `^`(x: vfloat, exp: static[int]): vfloat =
  22. when exp == 0:
  23. 1.0
  24. else:
  25. x
  26. proc `^`(x: vfloat, exp: static[float]): vfloat =
  27. when exp == 0.5:
  28. sqrt(x)
  29. else:
  30. pow(x, exp)
  31. proc `$`(x: vfloat): string =
  32. let y = cast[ptr float](addr x)
  33. result = $y[]
  34. let x = set1(9.0)
  35. echo x^0.5