
When an include is not surrounded by empty lines, its content is inlined on the same line as the adjacent content. That can lead to broken tags and other display issues. This PR fixes all such includes and introduces a validation step that forbids introducing the same problem again.
55 lines
1.5 KiB
Plaintext
55 lines
1.5 KiB
Plaintext
== Why is this an issue?
|
|
|
|
Floating point math is imprecise because of the challenges of storing such values in a binary representation. Even worse, floating point math is not associative; push a ``++Float++`` or a ``++Double++`` through a series of simple mathematical operations and the answer will be different based on the order of those operation because of the rounding that takes place at each step.
|
|
|
|
|
|
Even simple floating point assignments are not simple:
|
|
|
|
----
|
|
var f: Float = 0.1 // 0.1000000014901161193847656
|
|
var d: Double = 0.1 // 0.1000000000000000055511151
|
|
----
|
|
|
|
Therefore, the use of the equality (``++==++``) and inequality (``++!=++``) operators on ``++Float++`` or ``++Double++`` values is almost always an error.
|
|
|
|
|
|
This rule checks for the use of direct and indirect equality/inequailty tests on floats and doubles.
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,swift]
|
|
----
|
|
var myNumber: Float = 0.3 + 0.6
|
|
|
|
if myNumber == 0.9 { // Noncompliant. Because of floating point imprecision, this will be false
|
|
// ...
|
|
}
|
|
|
|
if myNumber <= 0.9 && myNumber >= 0.9 { // Noncompliant indirect equality test
|
|
// ...
|
|
}
|
|
|
|
if myNumber < 0.9 || myNumber > 0.9 { // Noncompliant indirect inequality test
|
|
// ...
|
|
}
|
|
----
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
Equality tests should not be made with floating point values.
|
|
|
|
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
include::../comments-and-links.adoc[]
|
|
|
|
endif::env-github,rspecator-view[]
|