@@ -33,6 +33,7 @@ type_alias! { "c_ulonglong.md", c_ulonglong = u64; }
3333
3434type_alias ! { "c_float.md" , c_float = f32 ; }
3535type_alias ! { "c_double.md" , c_double = f64 ; }
36+ type_alias ! { "c_longdouble.md" , c_longdouble = c_longdouble_definition:: c_longdouble; #[ doc( cfg( all( ) ) ) ] }
3637
3738mod c_char_definition {
3839 crate :: cfg_match! {
@@ -183,3 +184,57 @@ mod c_int_definition {
183184 }
184185 }
185186}
187+
188+ mod c_longdouble_definition {
189+ crate :: cfg_match! {
190+ any(
191+ // Windows and Apple use f64 across the board
192+ target_family = "windows" ,
193+ target_vendor = "apple" ,
194+ // FreeBSD-like operating systems use f64 on mips
195+ all(
196+ target_arch = "mips64" ,
197+ any( target_os = "freebsd" , target_os = "dragonfly" )
198+ ) ,
199+ ) => {
200+ pub ( super ) type c_longdouble = f64 ;
201+ }
202+ any( target_arch = "powerpc" , target_arch = "powerpc64" ) => {
203+ // double-double or f128 based on config
204+ compile_error!( "who knows" ) ;
205+ }
206+ any(
207+ target_arch = "aarch64" ,
208+ // Not yet implemented
209+ // target_arch = "loongarch32",
210+ target_arch = "loongarch64" ,
211+ target_arch = "mips64" ,
212+ target_arch = "riscv32" ,
213+ target_arch = "riscv64" ,
214+ target_arch = "s390x" ,
215+ target_arch = "wasm32" ,
216+ target_arch = "wasm64" ,
217+ // Note: mips32 with the N32 ABI is also f128 (?)
218+
219+ // Android and OpenHarmony use f128 on x86
220+ all(
221+ any( target_arch = "x86" , target_arch = "x86_64" ) ,
222+ any( target_os = "android" , target_env = "ohos" )
223+ ) ,
224+ // Default to f128 for other 64-bit targets
225+ all( not( target_arch = "x86_64" ) , target_pointer_width = "64" )
226+ ) => {
227+ pub ( super ) type c_longdouble = f128;
228+ }
229+ // Most other operating systems use the x87 80-bit extended precision float
230+ any( target_arch = "x86" , target_arch = "x86_64" ) => {
231+ // todo: obviously this isn't right
232+ pub ( super ) type c_longdouble = ( ) ;
233+ }
234+ // Most 16- and 32-bit targets use the same size as `c_double`, usually `f64` but
235+ // possibly `f32` on e.g. AVR.
236+ _ => {
237+ pub ( super ) type c_longdouble = c_double;
238+ }
239+ }
240+ }
0 commit comments