相关疑难解决方法(0)

如何计算(a次b)除以c仅使用32位整数类型,即使b次不适合这种类型

请考虑以下内容作为参考实现:

/* calculates (a * b) / c */
uint32_t muldiv(uint32_t a, uint32_t b, uint32_t c)
{
    uint64_t x = a;
    x = x * b;
    x = x / c;
    return x;
}
Run Code Online (Sandbox Code Playgroud)

我感兴趣的是一个不需要64位整数类型的实现(在C或伪代码中).

我开始草拟一个如下概述的实现:

/* calculates (a * b) / c */
uint32_t muldiv(uint32_t a, uint32_t b, uint32_t c)
{
    uint32_t d1, d2, d1d2;
    d1 = (1 << 10);
    d2 = (1 << 10);
    d1d2 = (1 << 20); /* d1 * d2 */
    return ((a / d1) …
Run Code Online (Sandbox Code Playgroud)

c integer integer-overflow multiplication integer-division

5
推荐指数
1
解决办法
3254
查看次数

C#中的角度测量仪

我想制作一个工具,可以测量表格上两个用户定义的点之间的角度.我目前没有代码可以执行此操作,因此任何代码都将受到赞赏.

谢谢

UPDATE

它需要以度为单位,我的点数是3个图片盒,每个图片盒的三个点都有不同的颜色供测量角度.

UPDATE

这是我当前的新代码:

namespace Angle_Measurer_Tool
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();                
        }

        int Dotter = 0;

        private void button1_Click(object sender, EventArgs e)
        {
            Dotter = 1;
        }

        public int Distance2D(int x1, int y1, int x2, int y2)
        {    
            int result = 0;
            double part1 = Math.Pow((x2 - x1), 2);

            double part2 = Math.Pow((y2 - y1), 2);
            double underRadical = part1 + part2;
            result = (int)Math.Sqrt(underRadical);

            return result;
        }

        private void pictureBox1_MouseClick(object …
Run Code Online (Sandbox Code Playgroud)

c# measurement angle winforms

0
推荐指数
1
解决办法
3207
查看次数