tstatic_with_converter.nim 717 B

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