是否有用于长类型的函数Math.Pow(A,n)?

编程入门 行业动态 更新时间:2024-10-10 23:21:45
本文介绍了是否有用于长类型的函数Math.Pow(A,n)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在测试一个小的C#程序片段:

I'm testing a small C# program fragment:

short min_short = (short)(int)-Math.Pow(2,15); short max_short = (short)(int)(Math.Pow(2, 15) - 1); Console.WriteLine("The min of short is:{0};\tThe max of short is:{1}", min_short, max_short); int min_int = (int)-Math.Pow(2, 31); int max_int = (int)(Math.Pow(2, 31) - 1); Console.WriteLine("The min of int is:{0};\tThe max of int is:{1}", min_int, max_int); uint min_uint = 0; uint max_uint = (uint)(Math.Pow(2, 32) - 1); Console.WriteLine("The min of uint is:{0};\tThe max of uint is:{1}", min_uint, max_uint); long min_long = (long)-Math.Pow(2, 63); long max_long = (long)(Math.Pow(2, 63) - 1); Console.WriteLine("The min of long is:{0};\tThe max of long is:{1}", min_long, max_long); ulong min_ulong = 0; ulong max_ulong = (ulong)(Math.Pow(2, 64) - 1); Console.WriteLine("The min of ulong is:{0};\tThe max of ulong is:{1}", min_ulong, max_ulong);

输出为:

The min of ushort is:0; The max of ushort is:65535 The min of short is:-32768; The max of short is:32767 The min of int is:-2147483648; The max of int is:2147483647 The min of uint is:0; The max of uint is:4294967295 The min of long is:-9223372036854775808;The max of long is:-9223372036854775808 The min of ulong is:0; The max of ulong is:0

我怀疑该错误是由Math.Pow()函数引起的,该函数返回的是双精度类型.

I suspect that the mistake is caused by the function of Math.Pow(),which is double type returned.

public static double Pow( double x, double y )

所以,我的问题是:长类型是否有类似的Math函数?如何更正上面程序片段中的错误.非常感谢!

so,my question is: Is there has a similar Math function for long type? How to correct the errors in the program fragment above. Many thanks!

推荐答案

您达到了 Math.Pow 的限制.您需要使用 System.Numerics.BigInteger.Pow .

You reached Math.Pow limit. You would need to use System.Numerics.BigInteger.Pow.

更多推荐

是否有用于长类型的函数Math.Pow(A,n)?

本文发布于:2023-11-22 01:38:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1615471.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:函数   类型   Pow   Math

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!