Fix -Werror=conversion in from_f64_to_u{16,32}
diff --git a/internal/cgen/base/floatconv-submodule-code.c b/internal/cgen/base/floatconv-submodule-code.c
index 603d180..e4b1a8f 100644
--- a/internal/cgen/base/floatconv-submodule-code.c
+++ b/internal/cgen/base/floatconv-submodule-code.c
@@ -22,7 +22,7 @@
if (sizeof(uint64_t) == sizeof(double)) {
memcpy(&u, &f, sizeof(uint64_t));
}
- uint16_t neg = ((uint16_t)(u >> 63)) << 15;
+ uint16_t neg = ((uint16_t)((u >> 63) << 15));
u &= 0x7FFFFFFFFFFFFFFF;
uint64_t exp = u >> 52;
uint64_t man = u & 0x000FFFFFFFFFFFFF;
@@ -58,7 +58,7 @@
// Convert from a 53-bit mantissa (after realizing the implicit bit) to a
// 10-bit mantissa and then adjust for the exponent.
man |= 0x0010000000000000;
- uint32_t shift = 1051 - exp; // 1051 = 0x3F0 + 53 - 10.
+ uint32_t shift = ((uint32_t)(1051 - exp)); // 1051 = 0x3F0 + 53 - 10.
uint64_t shifted_man = man >> shift;
wuffs_base__lossy_value_u16 ret;
ret.value = neg | ((uint16_t)shifted_man);
@@ -122,7 +122,7 @@
// Convert from a 53-bit mantissa (after realizing the implicit bit) to a
// 23-bit mantissa and then adjust for the exponent.
man |= 0x0010000000000000;
- uint32_t shift = 926 - exp; // 926 = 0x380 + 53 - 23.
+ uint32_t shift = ((uint32_t)(926 - exp)); // 926 = 0x380 + 53 - 23.
uint64_t shifted_man = man >> shift;
wuffs_base__lossy_value_u32 ret;
ret.value = neg | ((uint32_t)shifted_man);
diff --git a/internal/cgen/data/data.go b/internal/cgen/data/data.go
index 46320e0..5e8edb3 100644
--- a/internal/cgen/data/data.go
+++ b/internal/cgen/data/data.go
@@ -29,11 +29,11 @@
""
const BaseFloatConvSubmoduleCodeC = "" +
- "// ---------------- IEEE 754 Floating Point\n\nWUFFS_BASE__MAYBE_STATIC wuffs_base__lossy_value_u16 //\nwuffs_base__ieee_754_bit_representation__from_f64_to_u16_truncate(double f) {\n uint64_t u = 0;\n if (sizeof(uint64_t) == sizeof(double)) {\n memcpy(&u, &f, sizeof(uint64_t));\n }\n uint16_t neg = ((uint16_t)(u >> 63)) << 15;\n u &= 0x7FFFFFFFFFFFFFFF;\n uint64_t exp = u >> 52;\n uint64_t man = u & 0x000FFFFFFFFFFFFF;\n\n if (exp == 0x7FF) {\n if (man == 0) { // Infinity.\n wuffs_base__lossy_value_u16 ret;\n ret.value = neg | 0x7C00;\n ret.lossy = false;\n return ret;\n }\n // NaN. Shift the 52 mantissa bits to 10 mantissa bits, keeping the most\n // significant mantissa bit (quiet vs signaling NaNs). Also set the low 9\n // bits of ret.value so that the 10-bit mantissa is non-zero.\n wuffs_base__lossy_value_u16 ret;\n ret.value = neg | 0x7DFF | ((uint16_t)(man >> 42));\n ret.lossy = false;\n return ret;\n\n } else if (exp > 0x40E) { // Truncate to the largest finite f16.\n " +
- " wuffs_base__lossy_value_u16 ret;\n ret.value = neg | 0x7BFF;\n ret.lossy = true;\n return ret;\n\n } else if (exp <= 0x3E6) { // Truncate to zero.\n wuffs_base__lossy_value_u16 ret;\n ret.value = neg;\n ret.lossy = (u != 0);\n return ret;\n\n } else if (exp <= 0x3F0) { // Normal f64, subnormal f16.\n // Convert from a 53-bit mantissa (after realizing the implicit bit) to a\n // 10-bit mantissa and then adjust for the exponent.\n man |= 0x0010000000000000;\n uint32_t shift = 1051 - exp; // 1051 = 0x3F0 + 53 - 10.\n uint64_t shifted_man = man >> shift;\n wuffs_base__lossy_value_u16 ret;\n ret.value = neg | ((uint16_t)shifted_man);\n ret.lossy = (shifted_man << shift) != man;\n return ret;\n }\n\n // Normal f64, normal f16.\n\n // Re-bias from 1023 to 15 and shift above f16's 10 mantissa bits.\n exp = (exp - 1008) << 10; // 1008 = 1023 - 15 = 0x3FF - 0xF.\n\n // Convert from a 52-bit mantissa (excluding the implicit bit) to a 10-bit\n // mantissa (again excluding the implicit bi" +
- "t). We lose some information if\n // any of the bottom 42 bits are non-zero.\n wuffs_base__lossy_value_u16 ret;\n ret.value = neg | ((uint16_t)exp) | ((uint16_t)(man >> 42));\n ret.lossy = (man << 22) != 0;\n return ret;\n}\n\nWUFFS_BASE__MAYBE_STATIC wuffs_base__lossy_value_u32 //\nwuffs_base__ieee_754_bit_representation__from_f64_to_u32_truncate(double f) {\n uint64_t u = 0;\n if (sizeof(uint64_t) == sizeof(double)) {\n memcpy(&u, &f, sizeof(uint64_t));\n }\n uint32_t neg = ((uint32_t)(u >> 63)) << 31;\n u &= 0x7FFFFFFFFFFFFFFF;\n uint64_t exp = u >> 52;\n uint64_t man = u & 0x000FFFFFFFFFFFFF;\n\n if (exp == 0x7FF) {\n if (man == 0) { // Infinity.\n wuffs_base__lossy_value_u32 ret;\n ret.value = neg | 0x7F800000;\n ret.lossy = false;\n return ret;\n }\n // NaN. Shift the 52 mantissa bits to 23 mantissa bits, keeping the most\n // significant mantissa bit (quiet vs signaling NaNs). Also set the low 22\n // bits of ret.value so that the 23-bit mantissa is non-zero.\n wuffs_base__lo" +
- "ssy_value_u32 ret;\n ret.value = neg | 0x7FBFFFFF | ((uint32_t)(man >> 29));\n ret.lossy = false;\n return ret;\n\n } else if (exp > 0x47E) { // Truncate to the largest finite f32.\n wuffs_base__lossy_value_u32 ret;\n ret.value = neg | 0x7F7FFFFF;\n ret.lossy = true;\n return ret;\n\n } else if (exp <= 0x369) { // Truncate to zero.\n wuffs_base__lossy_value_u32 ret;\n ret.value = neg;\n ret.lossy = (u != 0);\n return ret;\n\n } else if (exp <= 0x380) { // Normal f64, subnormal f32.\n // Convert from a 53-bit mantissa (after realizing the implicit bit) to a\n // 23-bit mantissa and then adjust for the exponent.\n man |= 0x0010000000000000;\n uint32_t shift = 926 - exp; // 926 = 0x380 + 53 - 23.\n uint64_t shifted_man = man >> shift;\n wuffs_base__lossy_value_u32 ret;\n ret.value = neg | ((uint32_t)shifted_man);\n ret.lossy = (shifted_man << shift) != man;\n return ret;\n }\n\n // Normal f64, normal f32.\n\n // Re-bias from 1023 to 127 and shift above f32's 23 mantissa bit" +
- "s.\n exp = (exp - 896) << 23; // 896 = 1023 - 127 = 0x3FF - 0x7F.\n\n // Convert from a 52-bit mantissa (excluding the implicit bit) to a 23-bit\n // mantissa (again excluding the implicit bit). We lose some information if\n // any of the bottom 29 bits are non-zero.\n wuffs_base__lossy_value_u32 ret;\n ret.value = neg | ((uint32_t)exp) | ((uint32_t)(man >> 29));\n ret.lossy = (man << 35) != 0;\n return ret;\n}\n\n" +
+ "// ---------------- IEEE 754 Floating Point\n\nWUFFS_BASE__MAYBE_STATIC wuffs_base__lossy_value_u16 //\nwuffs_base__ieee_754_bit_representation__from_f64_to_u16_truncate(double f) {\n uint64_t u = 0;\n if (sizeof(uint64_t) == sizeof(double)) {\n memcpy(&u, &f, sizeof(uint64_t));\n }\n uint16_t neg = ((uint16_t)((u >> 63) << 15));\n u &= 0x7FFFFFFFFFFFFFFF;\n uint64_t exp = u >> 52;\n uint64_t man = u & 0x000FFFFFFFFFFFFF;\n\n if (exp == 0x7FF) {\n if (man == 0) { // Infinity.\n wuffs_base__lossy_value_u16 ret;\n ret.value = neg | 0x7C00;\n ret.lossy = false;\n return ret;\n }\n // NaN. Shift the 52 mantissa bits to 10 mantissa bits, keeping the most\n // significant mantissa bit (quiet vs signaling NaNs). Also set the low 9\n // bits of ret.value so that the 10-bit mantissa is non-zero.\n wuffs_base__lossy_value_u16 ret;\n ret.value = neg | 0x7DFF | ((uint16_t)(man >> 42));\n ret.lossy = false;\n return ret;\n\n } else if (exp > 0x40E) { // Truncate to the largest finite f16." +
+ "\n wuffs_base__lossy_value_u16 ret;\n ret.value = neg | 0x7BFF;\n ret.lossy = true;\n return ret;\n\n } else if (exp <= 0x3E6) { // Truncate to zero.\n wuffs_base__lossy_value_u16 ret;\n ret.value = neg;\n ret.lossy = (u != 0);\n return ret;\n\n } else if (exp <= 0x3F0) { // Normal f64, subnormal f16.\n // Convert from a 53-bit mantissa (after realizing the implicit bit) to a\n // 10-bit mantissa and then adjust for the exponent.\n man |= 0x0010000000000000;\n uint32_t shift = ((uint32_t)(1051 - exp)); // 1051 = 0x3F0 + 53 - 10.\n uint64_t shifted_man = man >> shift;\n wuffs_base__lossy_value_u16 ret;\n ret.value = neg | ((uint16_t)shifted_man);\n ret.lossy = (shifted_man << shift) != man;\n return ret;\n }\n\n // Normal f64, normal f16.\n\n // Re-bias from 1023 to 15 and shift above f16's 10 mantissa bits.\n exp = (exp - 1008) << 10; // 1008 = 1023 - 15 = 0x3FF - 0xF.\n\n // Convert from a 52-bit mantissa (excluding the implicit bit) to a 10-bit\n // mantissa (again excluding" +
+ " the implicit bit). We lose some information if\n // any of the bottom 42 bits are non-zero.\n wuffs_base__lossy_value_u16 ret;\n ret.value = neg | ((uint16_t)exp) | ((uint16_t)(man >> 42));\n ret.lossy = (man << 22) != 0;\n return ret;\n}\n\nWUFFS_BASE__MAYBE_STATIC wuffs_base__lossy_value_u32 //\nwuffs_base__ieee_754_bit_representation__from_f64_to_u32_truncate(double f) {\n uint64_t u = 0;\n if (sizeof(uint64_t) == sizeof(double)) {\n memcpy(&u, &f, sizeof(uint64_t));\n }\n uint32_t neg = ((uint32_t)(u >> 63)) << 31;\n u &= 0x7FFFFFFFFFFFFFFF;\n uint64_t exp = u >> 52;\n uint64_t man = u & 0x000FFFFFFFFFFFFF;\n\n if (exp == 0x7FF) {\n if (man == 0) { // Infinity.\n wuffs_base__lossy_value_u32 ret;\n ret.value = neg | 0x7F800000;\n ret.lossy = false;\n return ret;\n }\n // NaN. Shift the 52 mantissa bits to 23 mantissa bits, keeping the most\n // significant mantissa bit (quiet vs signaling NaNs). Also set the low 22\n // bits of ret.value so that the 23-bit mantissa is non-zero.\n " +
+ " wuffs_base__lossy_value_u32 ret;\n ret.value = neg | 0x7FBFFFFF | ((uint32_t)(man >> 29));\n ret.lossy = false;\n return ret;\n\n } else if (exp > 0x47E) { // Truncate to the largest finite f32.\n wuffs_base__lossy_value_u32 ret;\n ret.value = neg | 0x7F7FFFFF;\n ret.lossy = true;\n return ret;\n\n } else if (exp <= 0x369) { // Truncate to zero.\n wuffs_base__lossy_value_u32 ret;\n ret.value = neg;\n ret.lossy = (u != 0);\n return ret;\n\n } else if (exp <= 0x380) { // Normal f64, subnormal f32.\n // Convert from a 53-bit mantissa (after realizing the implicit bit) to a\n // 23-bit mantissa and then adjust for the exponent.\n man |= 0x0010000000000000;\n uint32_t shift = ((uint32_t)(926 - exp)); // 926 = 0x380 + 53 - 23.\n uint64_t shifted_man = man >> shift;\n wuffs_base__lossy_value_u32 ret;\n ret.value = neg | ((uint32_t)shifted_man);\n ret.lossy = (shifted_man << shift) != man;\n return ret;\n }\n\n // Normal f64, normal f32.\n\n // Re-bias from 1023 to 127 and shi" +
+ "ft above f32's 23 mantissa bits.\n exp = (exp - 896) << 23; // 896 = 1023 - 127 = 0x3FF - 0x7F.\n\n // Convert from a 52-bit mantissa (excluding the implicit bit) to a 23-bit\n // mantissa (again excluding the implicit bit). We lose some information if\n // any of the bottom 29 bits are non-zero.\n wuffs_base__lossy_value_u32 ret;\n ret.value = neg | ((uint32_t)exp) | ((uint32_t)(man >> 29));\n ret.lossy = (man << 35) != 0;\n return ret;\n}\n\n" +
"" +
"// --------\n\n#define WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__DECIMAL_POINT__RANGE 2047\n#define WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__DIGITS_PRECISION 800\n\n// WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__SHIFT__MAX_INCL is the largest N\n// such that ((10 << N) < (1 << 64)).\n#define WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__SHIFT__MAX_INCL 60\n\n// wuffs_base__private_implementation__high_prec_dec (abbreviated as HPD) is a\n// fixed precision floating point decimal number, augmented with ±infinity\n// values, but it cannot represent NaN (Not a Number).\n//\n// \"High precision\" means that the mantissa holds 800 decimal digits. 800 is\n// WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__DIGITS_PRECISION.\n//\n// An HPD isn't for general purpose arithmetic, only for conversions to and\n// from IEEE 754 double-precision floating point, where the largest and\n// smallest positive, finite values are approximately 1.8e+308 and 4.9e-324.\n// HPD exponents above +2047 mean infinity, below -2047 mean zero. The ±2047\n// bounds are further a" +
"way from zero than ±(324 + 800), where 800 and 2047 is\n// WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__DIGITS_PRECISION and\n// WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__DECIMAL_POINT__RANGE.\n//\n// digits[.. num_digits] are the number's digits in big-endian order. The\n// uint8_t values are in the range [0 ..= 9], not ['0' ..= '9'], where e.g. '7'\n// is the ASCII value 0x37.\n//\n// decimal_point is the index (within digits) of the decimal point. It may be\n// negative or be larger than num_digits, in which case the explicit digits are\n// padded with implicit zeroes.\n//\n// For example, if num_digits is 3 and digits is \"\\x07\\x08\\x09\":\n// - A decimal_point of -2 means \".00789\"\n// - A decimal_point of -1 means \".0789\"\n// - A decimal_point of +0 means \".789\"\n// - A decimal_point of +1 means \"7.89\"\n// - A decimal_point of +2 means \"78.9\"\n// - A decimal_point of +3 means \"789.\"\n// - A decimal_point of +4 means \"7890.\"\n// - A decimal_point of +5 means \"78900.\"\n//\n// As above, a decimal_point higher than +2047" +
diff --git a/release/c/wuffs-unsupported-snapshot.c b/release/c/wuffs-unsupported-snapshot.c
index 7a6e37f..d396668 100644
--- a/release/c/wuffs-unsupported-snapshot.c
+++ b/release/c/wuffs-unsupported-snapshot.c
@@ -9970,7 +9970,7 @@
if (sizeof(uint64_t) == sizeof(double)) {
memcpy(&u, &f, sizeof(uint64_t));
}
- uint16_t neg = ((uint16_t)(u >> 63)) << 15;
+ uint16_t neg = ((uint16_t)((u >> 63) << 15));
u &= 0x7FFFFFFFFFFFFFFF;
uint64_t exp = u >> 52;
uint64_t man = u & 0x000FFFFFFFFFFFFF;
@@ -10006,7 +10006,7 @@
// Convert from a 53-bit mantissa (after realizing the implicit bit) to a
// 10-bit mantissa and then adjust for the exponent.
man |= 0x0010000000000000;
- uint32_t shift = 1051 - exp; // 1051 = 0x3F0 + 53 - 10.
+ uint32_t shift = ((uint32_t)(1051 - exp)); // 1051 = 0x3F0 + 53 - 10.
uint64_t shifted_man = man >> shift;
wuffs_base__lossy_value_u16 ret;
ret.value = neg | ((uint16_t)shifted_man);
@@ -10070,7 +10070,7 @@
// Convert from a 53-bit mantissa (after realizing the implicit bit) to a
// 23-bit mantissa and then adjust for the exponent.
man |= 0x0010000000000000;
- uint32_t shift = 926 - exp; // 926 = 0x380 + 53 - 23.
+ uint32_t shift = ((uint32_t)(926 - exp)); // 926 = 0x380 + 53 - 23.
uint64_t shifted_man = man >> shift;
wuffs_base__lossy_value_u32 ret;
ret.value = neg | ((uint32_t)shifted_man);