math.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. do_div(num, 10);
  28. return num;
  29. }
  30. static inline u64 div_factor_fine(u64 num, int factor)
  31. {
  32. if (factor == 100)
  33. return num;
  34. num *= factor;
  35. do_div(num, 100);
  36. return num;
  37. }
  38. #endif