include::../description.adoc[]

== Noncompliant Code Example

----
void nonCompliant ( ) {
  float twoThirds = 2 / 3;
  long millisInYear = 1000 * 3600 * 24 * 365;
}
----

== Compliant Solution

----
void compliant1() {
  float twoThirds = 2.F / 3;
  long millisInYear = 1000L * 3600 * 24 * 365;
}
----
or

----
void compliant2() {
  float twoThirds = ((float) 2) / 3;
  long millisInYear = ((long) 1000) * 3600 * 24 * 365;
}
----

== See

* MISRA {cpp}:2008, 5-0-8 - An explicit integral or floating-point conversion shall not increase the size of the underlying type of a cvalue expression.
* http://cwe.mitre.org/data/definitions/190[MITRE, CWE-190] - Integer Overflow or Wraparound
* https://wiki.sei.cmu.edu/confluence/x/AjdGBQ[CERT, NUM50-J.] - Convert integers to floating point for floating-point operations
* https://wiki.sei.cmu.edu/confluence/x/I9cxBQ[CERT, INT18-C.] - Evaluate integer expressions in a larger size before comparing or assigning to that size
* https://www.sans.org/top25-software-errors/#cat2[SANS Top 25] - Risky Resource Management

ifdef::env-github,rspecator-view[]
'''
== Comments And Links
(visible only on this page)

include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]
