4 Replies - 281 Views - Last Post: 27 July 2012 - 03:11 PM Rate Topic: -----

#1 Raminator  Icon User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 205
  • Joined: 16-July 12

Problem with maths,or something else im not sure

Posted 20 July 2012 - 03:37 PM

Hey im making a program to solve 2ºGrade equations (like 2x²+2x+2) and i have come across a problem:What is the number inputed is too big for the double data type? i fixed it by adding an if statment where if the data input is bigger the a double can stand it will be stored on a long data type variable,but if i use the values that used to crash the program like A = 10E100 B = 10E300 C = 10E200 now it display the results as Delta = infinity X=infinity or X=-infinity.How can i fix this?
Here's the code for now.
Public Class Form1
    Dim i1 As Double
    Dim i2 As Double
    Dim i3 As Double
    Dim delta As Double
    Dim limit As Double = 1.7976931348623157E+308
    Dim x1 As Double
    Dim x2 As Double
    Dim leters As String
    Dim i12 As Long
    Dim i22 As Long
    Dim i32 As Long
    Dim delta2 As Long



    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        If (T1.Text > limit Or T2.Text > limit Or T3.Text > limit) Then
            i12 = T1.Text
            i22 = T2.Text
            i32 = T3.Text
            delta2 = (i22 * i22) - 4 * (i12 * i32)
            If (delta2 < 0) Then
                Ld.Text = delta2
                L1.Text = "Impossível"
                L2.Text = "Impossível"
            Else
                x1 = (-i22 + Math.Sqrt(delta2)) / (2 * i12)
                x2 = (-i22 - Math.Sqrt(delta2)) / (2 * i12)
                Ld.Text = delta2
                L1.Text = x1
                L2.Text = x2

            End If
        Else
            i1 = T1.Text
            i2 = T2.Text
            i3 = T3.Text
            delta = (i2 * i2) - 4 * (i1 * i3)
            If (delta < 0) Then
                Ld.Text = delta
                L1.Text = "Impossível"
                L2.Text = "Impossível"
            Else
                x1 = (-i2 + Math.Sqrt(delta)) / (2 * i1)
                x2 = (-i2 - Math.Sqrt(delta)) / (2 * i1)
                Ld.Text = delta
                L1.Text = x1
                L2.Text = x2

            End If

        End If

        
    End Sub

End Class

Attached image(s)

  • Attached Image


Is This A Good Question/Topic? 0
  • +

Replies To: Problem with maths,or something else im not sure

#2 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 547
  • View blog
  • Posts: 2,904
  • Joined: 19-May 09

Re: Problem with maths,or something else im not sure

Posted 20 July 2012 - 06:47 PM

This might be informative.
Was This Post Helpful? 0
  • +
  • -

#3 Raminator  Icon User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 205
  • Joined: 16-July 12

Re: Problem with maths,or something else im not sure

Posted 20 July 2012 - 08:09 PM

View PostBobRodes, on 20 July 2012 - 06:47 PM, said:

This might be informative.

i have read it but imdidnt quite understand where my problem is.
Was This Post Helpful? 0
  • +
  • -

#4 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 547
  • View blog
  • Posts: 2,904
  • Joined: 19-May 09

Re: Problem with maths,or something else im not sure

Posted 26 July 2012 - 08:31 AM

Well, the link explains that doubles set overflows to infinity. You haven't explained why that's a "problem" for you, so it's hard to explain how to "fix" it.
Was This Post Helpful? 0
  • +
  • -

#5 Raminator  Icon User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 205
  • Joined: 16-July 12

Re: Problem with maths,or something else im not sure

Posted 27 July 2012 - 03:11 PM

View PostBobRodes, on 26 July 2012 - 08:31 AM, said:

Well, the link explains that doubles set overflows to infinity. You haven't explained why that's a "problem" for you, so it's hard to explain how to "fix" it.

O man im sorry i just finished reading all the article.The problem is that i need the result not infinity i fixed it by adding an if statment that stores the values in a long if they are bigger then a double.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1