none
再建一个结构体,也是数字,怎么与其他数进行加减乘除? RRS feed

  • 问题

  • 起初,我在写小数换写成分数的函数,

    ulong[] Fr(ulong num ,byte loop);
    //把小数写成整数
    //loop是从右往左,循环位数

    我随机用23/97,20位小数都没有循环的迹象,我想位数不够。

    新建一种数的想法就有了。

    public struct Digit{
    	private ulong[] Bits8;//只用来表示小数
    }

    如何与其他数加减乘除?

    2022年2月24日 23:46

全部回复

  • 起初,我在写小数换写成分数的函数,

    ulong[] Fr(ulong num ,byte loop);
    //把小数写成整数
    //loop是从右往左,循环位数

    我随机用23/97,20位小数都没有循环的迹象,我想位数不够。

    新建一种数的想法就有了。

    public struct Digit{
    	private ulong[] Bits8;//只用来表示小数
    }

    如何与其他数加减乘除?

    你好 czhch,

    请问您想做得事情是什么?

    您能解释一下您得备注和您遇到得错误吗?有没有实际操作?

    您得小数与其它数加减乘除,是指和什么类型得数呢?

    经过我们得讨论,我们不太理解您想要完成的工作。

    Best Regards,

    Jiale


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2022年2月25日 1:57
  • 其实我在考虑怎样把这个数保存起来,思路是,

    Digit(int n){ Bits=new ulong[n];
    for(int u=0;u<64;u++){
    if(this-Math.Pow(2,-(u+1))>0)Bits64[0]+=Math.Pow(2,63-u);//相减大于0,-(u+1)有数是1
    //新定义的结构体不能作减法

    }

    怎么存入内存?


    • 已编辑 czhch 2022年2月25日 5:39 aa
    2022年2月25日 5:39
  • 您好 czhch,

    您说得怎么存入内存是什么意思?

    您对This的定义是什么?Bits64[0]又是什么?

    从您的代码来看,如果想保存,不能这样做吗?

    if(this-Math.Pow(2,-(u+1))>0){

    Bits64[0]+=Math.Pow(2,63-u); 

    }else{

    var result=Bits64[0];
    }       

    Best Regards,

    Jiale


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2022年2月25日 8:37
  • 再建一个结构体,我的目标就是让小数点后面再多几位,起码要50位。

    怎么办?

    2022年2月26日 7:29
  • 你是想实现一种数据格式,它能够储存 50 位小数,并且能够和系统的 float、double 类型进行运算吗?

    重载运算符能够使得自定义 struct 和 系统类型进行运算        

    public static Digit operator +(Digit P1, float P2) {
       Digit digit = new Digit();
    
        //或许你需要自己实现
        //如何进行对于 Digit 和 float 的「加法」运算。
    
       return new digit;  
    }

    你或许需要自己实现这些算法

    2022年8月28日 17:07
  • 不是特别明白你的问题,不过要实现自己的数据类型的加减,可以重载运算符,实现自己就行;

    family as water

    2022年9月13日 1:14