t18103.nim 720 B

123456789101112131415161718192021222324252627282930313233343536
  1. discard """
  2. targets: "c cpp"
  3. matrix: "--mm:refc; --mm:arc"
  4. """
  5. import base64, complex, sequtils, math, sugar
  6. type
  7. FP = float
  8. T = object
  9. index: int
  10. arg: FP
  11. val: Complex[FP]
  12. M = object
  13. alpha, beta: FP
  14. func a(s: openArray[T], model: M): seq[T] =
  15. let f = (tn: int) => model.alpha + FP(tn) * model.beta;
  16. return mapIt s:
  17. block:
  18. let s = it.val * rect(1.0, - f(it.index))
  19. T(index: it.index, arg: phase(s), val: s)
  20. proc b(): float64 =
  21. var s = toSeq(0..10).mapIt(T(index: it, arg: 1.0, val: complex.complex(1.0)))
  22. discard a(s, M(alpha: 1, beta: 1))
  23. return 1.0
  24. func cc(str: cstring, offset: ptr[cdouble]): cint {.exportc.} =
  25. offset[] = b()
  26. return 0
  27. static:
  28. echo b()