Start here

Home
About Klocwork
What's new
Fixed issues
Release notes
Installation

Reference

C/C++ checkers
Java checkers
C# checkers
MISRA C 2004 checkers
MISRA C++ 2008 checkers
MISRA C 2012 checkers
MISRA C 2012 checkers with Amendment 1
Commands
Metrics
Troubleshooting
Reference

Product components

C/C++ Integration build analysis
Java Integration build analysis
Desktop analysis
Refactoring
Klocwork Static Code Analysis
Klocwork Code Review
Structure101
Tuning
Custom checkers

Coding environments

Visual Studio
Eclipse for C/C++
Eclipse for Java
IntelliJ IDEA
Other

Administration

Project configuration
Build configuration
Administration
Analysis performance
Server performance
Security/permissions
Licensing
Klocwork Static Code Analysis Web API
Klocwork Code Review Web API

Community

View help online
Visit RogueWave.com
Klocwork Support
Rogue Wave Videos

Legal

Legal information

MISRA.CAST.FLOAT

Non-trivial float expression is cast to a wider type.

MISRA-C Rule 10.4 (required): The value of a complex expression of floating type shall only be cast to a floating type that is narrower or of the same size.

If a cast is to be used on any complex expression, the type of cast that may be applied is severely restricted. As explained in section 6.10, conversions on complex expressions are often a source of confusion and it is therefore wise to be cautious. In order to comply with these rules, it may be necessary to use a temporary variable and introduce an extra statement.

Example

... (float32_t)(f64a + f64b)              /* compliant     */
... (float64_t)(f32a + f32b)              /* not compliant */
... (float64_t)f32a                       /* compliant     */
... (float64_t)(s32a / s32b)              /* not compliant */
... (float64_t)(s32a > s32b)              /* not compliant */
... (float64_t)s32a / (float32_t)s32b     /* compliant     */
... (uint32_t)(u16a + u16b)               /* not compliant */
... (uint32_t)u16a + u16b                 /* compliant     */
... (uint32_t)u16a + (uint32_t)u16b       /* compliant     */
... (int16_t)(s32a - 12345)               /* compliant     */
... (uint8_t)(u16a * u16b)                /* compliant     */
... (uint16_t)(u8a * u8b)                 /* not compliant */
... (int16_t)(s32a * s32b)                /* compliant     */
... (int32_t)(s16a * s16b)                /* not compliant */
... (uint16_t)(f64a + f64b)               /* not compliant */
... (float32_t)(u16a + u16b)              /* not compliant */
... (float64_t)foo1(u16a + u16b)          /* compliant     */
... (int32_t)buf16a[u16a + u16b]          /* compliant     */