Swift support for long double/Float80 math functions?


(Antonino) #1

How make Float80 bridge with long double math.h c functions?

I resorts to use some orrible hacks like these:

// in f80.h
extern void sqrt_f80( void *result, const void *v );
extern void pow_f80( void *result, const void *v, const void *e );
...

// in f80.c
void sqrt_f80( void *result, const void *v ) { *(long double *)result = sqrtl( *(const long double *)v ); }
void pow_f80( void *result, const void *v, const void *e ) { *(long double *)result = powl( *(const long double *)v,*(const long double *)e ); }

// in f80.swift
func sqrt( _ a:Float80 ) -> Float80 { var result = Float80(); var v = a; sqrt_f80( &result, &v ); return result; }
func pow( _ a:Float80,_ e:Float80 ) -> Float80 { var result = Float80(); var v1 = a; var v2 = e; pow_f80( &result, &v1, &v2 ); return result; }

There is an easier way?

P.S. Sorry for my bad english.