mirror of
https://github.com/cc65/cc65.git
synced 2025-01-13 09:31:53 +00:00
Suppress the floating point precision warning if an explicit cast is used
This commit is contained in:
parent
e3887d7ead
commit
2ac9c6f51e
@ -55,7 +55,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void DoConversion (ExprDesc* Expr, const Type* NewType)
|
static void DoConversion (ExprDesc* Expr, const Type* NewType, int Explicit)
|
||||||
/* Emit code to convert the given expression to a new type. */
|
/* Emit code to convert the given expression to a new type. */
|
||||||
{
|
{
|
||||||
const Type* OldType;
|
const Type* OldType;
|
||||||
@ -128,8 +128,9 @@ static void DoConversion (ExprDesc* Expr, const Type* NewType)
|
|||||||
*/
|
*/
|
||||||
if (IsClassFloat (OldType) && IsClassInt (NewType)) {
|
if (IsClassFloat (OldType) && IsClassInt (NewType)) {
|
||||||
long IVal = (long)Expr->V.FVal.V;
|
long IVal = (long)Expr->V.FVal.V;
|
||||||
if (Expr->V.FVal.V != FP_D_FromInt(IVal).V)
|
if ((Expr->V.FVal.V != FP_D_FromInt(IVal).V) && !Explicit) {
|
||||||
Warning ("Floating point constant (%f) converted to integer loses precision (%d)",Expr->V.FVal.V,IVal);
|
Warning ("Floating point constant (%f) converted to integer loses precision (%d)",Expr->V.FVal.V,IVal);
|
||||||
|
}
|
||||||
Expr->IVal = IVal;
|
Expr->IVal = IVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -293,7 +294,7 @@ void TypeConversion (ExprDesc* Expr, const Type* NewType)
|
|||||||
/* Both types must be complete */
|
/* Both types must be complete */
|
||||||
if (!IsIncompleteESUType (NewType) && !IsIncompleteESUType (Expr->Type)) {
|
if (!IsIncompleteESUType (NewType) && !IsIncompleteESUType (Expr->Type)) {
|
||||||
/* Do the actual conversion */
|
/* Do the actual conversion */
|
||||||
DoConversion (Expr, NewType);
|
DoConversion (Expr, NewType, 0);
|
||||||
} else {
|
} else {
|
||||||
/* We should have already generated error elsewhere so that we
|
/* We should have already generated error elsewhere so that we
|
||||||
** could just silently fail here to avoid excess errors, but to
|
** could just silently fail here to avoid excess errors, but to
|
||||||
@ -340,7 +341,7 @@ void TypeCast (ExprDesc* Expr)
|
|||||||
ReplaceType (Expr, NewType);
|
ReplaceType (Expr, NewType);
|
||||||
} else if (IsCastType (Expr->Type)) {
|
} else if (IsCastType (Expr->Type)) {
|
||||||
/* Convert the value. The result has always the new type */
|
/* Convert the value. The result has always the new type */
|
||||||
DoConversion (Expr, NewType);
|
DoConversion (Expr, NewType, 1);
|
||||||
} else {
|
} else {
|
||||||
TypeCompatibilityDiagnostic (NewType, Expr->Type, 1,
|
TypeCompatibilityDiagnostic (NewType, Expr->Type, 1,
|
||||||
"Cast to incompatible type '%s' from '%s'");
|
"Cast to incompatible type '%s' from '%s'");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user