32位处理器上的64位/64位余数查找算法? [英] 64 bit / 64 bit remainder finding algorithm on a 32 bit processor?

查看:228
本文介绍了32位处理器上的64位/64位余数查找算法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道过去也曾问过类似的问题,但是经过长时间的处理,我实现了使用重复减法除法来正确找到的算法.但是我无法从这种方法中找出剩余.是否有任何快速简便的方法来找出32位处理器上64位/64位除法中的余数.更准确地说,我正在尝试实现

I know that similar questions has been asked in the past, but I have implemented after a long process the algorithm to find the quotient correctly using the division by repeated subtraction method. But I am not able to find out the remainder from this approach. Is there any quick and easy way for finding out remainder in 64bit/64bit division on 32bit processor. To be more precise I am trying to implement

ulldiv_t __aeabi_uldivmod(  
 unsigned long long n, unsigned long long d)  

本文档中引用的 http://infocenter .arm.com/help/topic/com.arm.doc.ihi0043d/IHI0043D_rtabi.pdf

推荐答案

什么?如果您重复进行减法运算(听起来确实很基础),那么剩下的难道不是就和剩下的一样简单吗?

What? If you do repeated subtraction (which sounds really basic), then isn't it as simple as whatever you have left when you can't do another subtraction is the remainder?

至少这是幼稚的直观方式:

At least that's the naïve intuitive way:

uint64_t simple_divmod(uint64_t n, uint64_t d)
{
  if (n == 0 || d == 0)
    return 0;
  uint64_t q = 0;
  while (n >= d)
  {
    ++q;
    n -= d;
  }
  return n;
}

还是我想念小船,在这里?

Or am I missing the boat, here?

当然,对于大量用户,这将非常慢,但这是重复的减法.我敢肯定(甚至不看!)还有更高级的算法.

Of course this will be fantastically slow for large numbers, but this is repeated subtraction. I'm sure (even without looking!) there are more advanced algorithms.

这篇关于32位处理器上的64位/64位余数查找算法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆