rspec/rules/S2184/description.adoc

8 lines
738 B
Plaintext
Raw Normal View History

2021-01-27 13:42:22 +01:00
When arithmetic is performed on integers, the result will always be an integer. You can assign that result to a ``++long++``, ``++double++``, or ``++float++`` with automatic type conversion, but having started as an ``++int++`` or ``++long++``, the result will likely not be what you expect.
2020-06-30 12:48:07 +02:00
2021-02-02 15:02:10 +01:00
2021-01-27 13:42:22 +01:00
For instance, if the result of ``++int++`` division is assigned to a floating-point variable, precision will have been lost before the assignment. Likewise, if the result of multiplication is assigned to a ``++long++``, it may have already overflowed before the assignment.
2020-06-30 12:48:07 +02:00
2021-02-02 15:02:10 +01:00
2020-06-30 12:48:07 +02:00
In either case, the result will not be what was expected. Instead, at least one operand should be cast or promoted to the final type before the operation takes place.