如何在C#中找到计算器中sqrt的sqrt [英] How to find a sqrt of an sqrt in calculator in C#

查看:114
本文介绍了如何在C#中找到计算器中sqrt的sqrt的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C#windows应用程序中设计一个计算器。有人可以帮我找一个squreroot值的squareroot值。例如(srqt(2)= 1.414)如果我想要这个1.414的srqureroot是什么代码我应该写..



我尝试过:



我我在C#windows应用程序中设计一个计算器。有人可以帮我找一个squreroot值的squareroot值。例如(srqt(2)= 1.414)如果我想要这个1.414的srqureroot应该写什么代码。 。

I am designing a calculator in C# windows application..Could anyone please help me to find the squareroot value of an squreroot value..for example(srqt(2)=1.414)if i want the srqureroot of this 1.414 what code should i write..

What I have tried:

I am designing a calculator in C# windows application..Could anyone please help me to find the squareroot value of an squreroot value..for example(srqt(2)=1.414)if i want the srqureroot of this 1.414 what code should i write..

推荐答案

尝试:

Try:
double x = Math.Sqrt(Math.Sqrt(2));



Or

double x = Math.Pow(2, 1.0 / 4);


As OriginalGriff ju st告诉你,PPolymorphe只是建议你,这是一个非常简单的计算。



这是一个想法:假设你有一个记忆存储按钮,你可能会让你计算器通过实现以任意值作为指数和根输入的POW和RT功能按钮,为其用户提供zingy-mint-all-over感觉。



考虑
As OriginalGriff just showed you, and PPolymorphe just advised you, this is a very simple calculation.

Here's a thought: assuming you have a memory-store button, you might make your calculator give its users that zingy-mint-all-over feeling by implementing POW and RT function buttons that take arbitrary values as exponent and root inputs.

Consider
double pow1 = Math.Pow(8.0, 4.0);         // => 4096
double root1 = Math.Pow(pow1, 1.0/4.0);   // => 8.0

double pow2 = Math.Pow(13.0, 5.0);        // => 371293.0
double root2 = Math.Pow(pow2, 1.0 / 5.0); // => 13.000000000000002

事情变得有趣的是处理负值:

Where things get interesting is in dealing with negative values:

public double NPOW(double toraise, double raiseto)
{
    return (toraise < 0)
        ? -1*Math.Pow(Math.Abs(toraise), raiseto)
        : Math.Pow(toraise, raiseto);
}

//test
// double pow3 = NPOW(-13.0, 4.0);   // => -28561.0
// double root3 = NPOW(pow3, .25);   // => -13.0

根据您使用负数输入的操作,此函数可能会返回您应该能够处理的NaN结果(并且这很好,因为这意味着您没有得到错误抛出)。关于除以0.0的常见注意事项。



请记住,如果您使用Math.Pow函数通过提供小数值作为指数来获取根,那么你必须小心确保你所做的任何除法产生分数指数得到的是双倍而不是整数。

Depending on what you do with negative number inputs this function may return a NaN result which you should be able to handle (and, that's good because it means you don't get an error thrown). The usual cautions about dividing by 0.0.

Keep in mind that if you do use the Math.Pow function to get roots by supplying a fractional value as the exponent, that you must be careful to make sure any division you do to produce that fractional exponent results in a double, not an integer.


这篇关于如何在C#中找到计算器中sqrt的sqrt的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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