math.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. * Copyright (C) 2012 Fujitsu. All rights reserved.
  3. * Written by Miao Xie <miaox@cn.fujitsu.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public
  7. * License v2 as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public
  15. * License along with this program; if not, write to the
  16. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  17. * Boston, MA 021110-1307, USA.
  18. */
  19. #ifndef __BTRFS_MATH_H
  20. #define __BTRFS_MATH_H
  21. #include <asm/div64.h>
  22. static inline u64 div_factor(u64 num, int factor)
  23. {
  24. if (factor == 10)
  25. return num;
  26. num *= factor;
  27. return div_u64(num, 10);
  28. }
  29. static inline u64 div_factor_fine(u64 num, int factor)
  30. {
  31. if (factor == 100)
  32. return num;
  33. num *= factor;
  34. return div_u64(num, 100);
  35. }
  36. #endif