1 Complex arguments and return values of C functions are represented as 2 [ real, imaginary ] arrays. 3 4 Call libc functions taking and returning float and double complex values. 5 6 -- Testcase -- 7 {% 8 import * as ffi from 'ffi'; 9 10 let cabs = ffi.C.wrap('double cabs(double complex)'); 11 let cabsf = ffi.C.wrap('float cabsf(float complex)'); 12 let cimag = ffi.C.wrap('double cimag(double complex)'); 13 let crealf = ffi.C.wrap('float crealf(float complex)'); 14 let conj = ffi.C.wrap('double complex conj(double complex)'); 15 let conjf = ffi.C.wrap('float complex conjf(float complex)'); 16 let cproj = ffi.C.wrap('double complex cproj(double complex)'); 17 18 print("cabs: ", cabs([ 3.0, 4.0 ]), "\n"); 19 print("cabsf: ", cabsf([ 6.0, 8.0 ]), "\n"); 20 print("cimag: ", cimag([ 1.5, -2.5 ]), "\n"); 21 print("crealf: ", crealf([ 1.5, -2.5 ]), "\n"); 22 print("conj: ", conj([ 3.0, 4.0 ]), "\n"); 23 print("conjf: ", conjf([ 1.5, -2.5 ]), "\n"); 24 print("cproj: ", cproj([ -0.5, 0.25 ]), "\n"); 25 -- End -- 26 27 -- Expect stdout -- 28 cabs: 5 29 cabsf: 10 30 cimag: -2.5 31 crealf: 1.5 32 conj: [ 3.0, -4.0 ] 33 conjf: [ 1.5, 2.5 ] 34 cproj: [ -0.5, 0.25 ] 35 -- End --
This page was automatically generated by LXR 0.3.1. • OpenWrt