mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-29 10:50:05 +00:00
Endian specific floating point types (e.g. f32be)
This commit is contained in:
@@ -1802,6 +1802,12 @@ fmt_arg :: proc(fi: ^Info, arg: any, verb: rune) {
|
||||
case f32: fmt_float(fi, f64(a), 32, verb);
|
||||
case f64: fmt_float(fi, a, 64, verb);
|
||||
|
||||
case f32le: fmt_float(fi, f64(a), 32, verb);
|
||||
case f64le: fmt_float(fi, f64(a), 64, verb);
|
||||
|
||||
case f32be: fmt_float(fi, f64(a), 32, verb);
|
||||
case f64be: fmt_float(fi, f64(a), 64, verb);
|
||||
|
||||
case complex64: fmt_complex(fi, complex128(a), 64, verb);
|
||||
case complex128: fmt_complex(fi, a, 128, verb);
|
||||
|
||||
|
||||
@@ -363,6 +363,11 @@ write_type :: proc(buf: ^strings.Builder, ti: ^Type_Info) {
|
||||
case Type_Info_Float:
|
||||
write_byte(buf, 'f');
|
||||
write_i64(buf, i64(8*ti.size), 10);
|
||||
switch info.endianness {
|
||||
case .Platform: // Okay
|
||||
case .Little: write_string(buf, "le");
|
||||
case .Big: write_string(buf, "be");
|
||||
}
|
||||
case Type_Info_Complex:
|
||||
write_string(buf, "complex");
|
||||
write_i64(buf, i64(8*ti.size), 10);
|
||||
|
||||
@@ -57,7 +57,7 @@ Type_Info_Struct_Soa_Kind :: enum u8 {
|
||||
Type_Info_Named :: struct {name: string, base: ^Type_Info};
|
||||
Type_Info_Integer :: struct {signed: bool, endianness: Platform_Endianness};
|
||||
Type_Info_Rune :: struct {};
|
||||
Type_Info_Float :: struct {};
|
||||
Type_Info_Float :: struct {endianness: Platform_Endianness};
|
||||
Type_Info_Complex :: struct {};
|
||||
Type_Info_Quaternion :: struct {};
|
||||
Type_Info_String :: struct {is_cstring: bool};
|
||||
|
||||
@@ -18,6 +18,22 @@ bswap_128 :: proc "none" (x: u128) -> u128 {
|
||||
return u128(bswap_64(u64(x))) | u128(bswap_64(u64(x>>64)));
|
||||
}
|
||||
|
||||
|
||||
bswap_f32 :: proc "none" (f: f32) -> f32 {
|
||||
x := transmute(u32)f;
|
||||
z := x>>24 | (x>>8)&0xff00 | (x<<8)&0xff0000 | x<<24;
|
||||
return transmute(f32)z;
|
||||
|
||||
}
|
||||
|
||||
bswap_f64 :: proc "none" (f: f64) -> f64 {
|
||||
x := transmute(u64)f;
|
||||
z := u64(bswap_32(u32(x))) | u64(bswap_32(u32(x>>32)));
|
||||
return transmute(f64)z;
|
||||
}
|
||||
|
||||
|
||||
|
||||
ptr_offset :: inline proc "contextless" (ptr: $P/^$T, n: int) -> P {
|
||||
new := int(uintptr(ptr)) + size_of(T)*n;
|
||||
return P(uintptr(new));
|
||||
|
||||
Reference in New Issue
Block a user