tstatic_with_converter.nim 780 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. # xxx not sure if intentional in this issue, but this returns ""
  34. echo y[]
  35. let x = set1(9.0)
  36. echo x^0.5