func init() { var fin = func(f *C.mpf_t) { C.mpf_init(&(*f)[0]) } fin(&a) fin(&b) fin(&cx) fin(&cy) fin(&x) fin(&y) }
// Int promises that the zero value is a 0, but in gmp // the zero value is a crash. To bridge the gap, the // init bool says whether this is a valid gmp value. // doinit initializes f.i if it needs it. This is not inherent // to FFI, just a mismatch between Go's convention of // making zero values useful and gmp's decision not to. func (f *Float) doinit() { if f.init { return } if f.prec != 0 { C.mpf_init2(&f.i[0], C.mp_bitcnt_t(f.prec)) } else { C.mpf_init(&f.i[0]) } f.init = true }
//every float created must be created here! func newFloat() *Float { var this = new(Float) garbage[this] = true C.mpf_init(&this.i[0]) return this }