LCOV - code coverage report
Current view: top level - gfx/2d - NumericTools.h (source / functions) Hit Total Coverage
Test: output.info Lines: 9 10 90.0 %
Date: 2017-07-14 16:53:18 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
       2             :  * This Source Code Form is subject to the terms of the Mozilla Public
       3             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       4             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       5             : 
       6             : #ifndef MOZILLA_GFX_NUMERICTOOLS_H_
       7             : #define MOZILLA_GFX_NUMERICTOOLS_H_
       8             : 
       9             : namespace mozilla {
      10             : 
      11             : // XXX - Move these into mfbt/MathAlgorithms.h?
      12             : 
      13             : // Returns the largest multiple of aMultiplied that's <= x.
      14             : // Same as int32_t(floor(double(x) / aMultiplier)) * aMultiplier,
      15             : // but faster.
      16             : inline int32_t
      17         638 : RoundDownToMultiple(int32_t x, int32_t aMultiplier)
      18             : {
      19             :   // We don't use float division + floor because that's hard for the compiler
      20             :   // to optimize.
      21         638 :   int mod = x % aMultiplier;
      22         638 :   if (x > 0) {
      23         559 :     return x - mod;
      24             :   }
      25          79 :   return mod ? x - aMultiplier - mod : x;
      26             : }
      27             : 
      28             : // Returns the smallest multiple of aMultiplied that's >= x.
      29             : // Same as int32_t(ceil(double(x) / aMultiplier)) * aMultiplier,
      30             : // but faster.
      31             : inline int32_t
      32         612 : RoundUpToMultiple(int32_t x, int32_t aMultiplier)
      33             : {
      34         612 :   int mod = x % aMultiplier;
      35         612 :   if (x > 0) {
      36         612 :     return mod ? x + aMultiplier - mod : x;
      37             :   }
      38           0 :   return x - mod;
      39             : }
      40             : 
      41             : } // namespace mozilla
      42             : 
      43             : #endif /* MOZILLA_GFX_NUMERICTOOLS_H_ */

Generated by: LCOV version 1.13