Created
April 25, 2014 11:51
-
-
Save KittyGiraudel/11286934 to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ---- | |
| // Sass (v3.3.5) | |
| // Compass (v1.0.0.alpha.18) | |
| // ---- | |
| // Because of the way floats work in any language | |
| // You cannot expect a float to be precise. | |
| // --- | |
| // While one could expect 0.12 to equal 0.10 + 0.02 | |
| // Unfortunately, it is not. | |
| // --- | |
| // Hence a little function to check whether 2 floats are equal or not | |
| // Inspired by: https://github.com/nex3/sass/issues/1224 | |
| // --- | |
| // @param [number] $a: first number | |
| // @param [number] $b: second number | |
| // @param [number] $tolerance: tolerance (epsilon) | |
| // --- | |
| // @return [bool] | |
| @function approximately-equal($a, $b, $tolerance: 0.0000001) { | |
| @return abs($a - $b) <= $tolerance; | |
| } | |
| // Alias | |
| @function a-equal($a, $b, $tolerance: 0.0000001) { | |
| @return approximately-equal($a, $b, $tolerance); | |
| } | |
| // Test | |
| test { | |
| $a: 0.12; | |
| $b: 0.10 + 0.02; | |
| bug: $a == $b; | |
| fix: approximately-equal($a, $b); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| test { | |
| bug: false; | |
| fix: true; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment