using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
double x, y;
public Form1()
{
InitializeComponent();
// Initialize input points to zero
textBox1.Text = "0";
textBox2.Text = "0";
x = Double.Parse(textBox1.Text);
y = Double.Parse(textBox2.Text);
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
x = Double.Parse(textBox1.Text);
y = Double.Parse(textBox2.Text);
if (radioButton1.Checked)
{
x = x/(System.Math.Pow(x, 2) + System.Math.Pow(y, 2));
y = -y/(System.Math.Pow(x, 2) + System.Math.Pow(y, 2));
textBox1.Text = x.ToString();
textBox2.Text = y.ToString();
}
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
x = Double.Parse(textBox1.Text);
y = Double.Parse(textBox2.Text);
if (radioButton2.Checked)
{
x = x/(System.Math.Pow(x, 2) + System.Math.Pow(y, 2));
y = -y/(System.Math.Pow(x, 2) + System.Math.Pow(y, 2));
textBox1.Text = x.ToString();
textBox2.Text = y.ToString();
}
}
}
}
我試圖「重新模擬」我的問題,這裏是代碼。嘗試在每個文本框中輸入1的值,然後單擊未選中的單選按鈕。 textbox1的預期輸出應該是0.5,textbox2應該給-0.5,但是我在textbox2中得到-0.8。C#錯誤的數學結果
無法重現。完整的代碼示例或它沒有發生。 – sepp2k
適用於我 - .NET 4 - 結果**是** -0.5 .... –
這裏沒有錯誤([在線演示](http://ideone.com/cPSHv),使用喬恩的代碼) – Nasreddine