0

This is a Math question, but to try to solve a C# Programming issue so I am not sure if here is the best place for it.

In the following code, I can get the Derivative:

var x = 13.399E+153;
var d = ((1 + x) * (1 - x));
Console.WriteLine("d = {0:0}", d);
Console.ReadLine();

Where 13.399E+153; the 9's are recurring. But if x becomes:

var x = 14.00E+153;

I get -Infinity. I have done some research already but do not understand any possible solution.

URL: Mathematical function differentiation with C#? also: Limit of the derivative of a function as x goes to infinity I do understand why this is ocurring however:

If the limit of f(x) f(x) exists, there is a horizontal asymptote. 
Therefore as the function approaches infinity it becomes more linear and 
...thus the derivative approaches zero. 
.

My question is, if I am returning the Derivative as a double for example, what would a solution be to prevent it being returned as Infinity? Should I return 1, or Zero?

if (double.IsInfinity(Derivative))
{
return ?;
}
Community
  • 1
  • 1
Rusty Nail
  • 2,692
  • 3
  • 34
  • 55
  • 1
    Should I return 1, or Zero? It could be 1, 0, or -1 or anything really. It up to you to handle the return value. You also could just return `double.IsInfinity(Derivative)` and `out` the derivative value from the method call. – Tdorno Feb 23 '16 at 00:26
  • 1
    Maybe use [`BigRational`](http://bcl.codeplex.com/releases/view/42782) instead of just a `double`. But one wonders to which exponent are you willing to go? – Dialecticus Feb 23 '16 at 00:29
  • 42 is the answer... I have no idea what you are actually hope to achieve with returning some finite value for infinity. If you really need to you have to explicitly support concept of "infinity" in your computations. – Alexei Levenkov Feb 23 '16 at 01:03

1 Answers1

0

You get the result of negative Infinity because the mathematical value of the result is less than the least value that can be represented using 64 bit floating point numbers. This is completely normal, I see nothing that needs to be fixed.

Joni
  • 108,737
  • 14
  • 143
  • 193
  • This is what I already know, it does not give me a solution. I can not return Infinity - or + I need to return a value that will not break the math. – Rusty Nail Feb 23 '16 at 00:25
  • How does returning Infinity break the math in a way that returning something else does not? – Joni Feb 23 '16 at 00:27
  • Well, thats really the Question I have already asked isnt it! – Rusty Nail Feb 23 '16 at 00:30
  • Let me rephrase. What do you mean by math being "broken"? – Joni Feb 23 '16 at 00:32
  • In mathematics, "infinity" is often treated as if it were a number (i.e., it counts or measures things: "an infinite number of terms") but it is not the same sort of number as natural or real numbers. One can not Do Math with Infinity! – Rusty Nail Feb 23 '16 at 00:38
  • 1
    Wouldn't returning any valid `Double` value actually break the math, because that wouldn't actually be the correct answer? The result is -1,96E+308, but this does not fall in the range of a `Double`, so considering the limitations of storing numeric data, minus infinity is actually the best you can get. Would you consider using another datatype than `Double`? – xjuice Feb 23 '16 at 00:54
  • 1
    @Chris, you have to accept that floating point numbers are not real numbers. Many theorems that apply to real numbers don't apply to floating point. Positive and negative infinity are valid floating point numbers and you can use them arithmetic like any others. – Joni Feb 23 '16 at 07:51
  • @Joni - I dont dissagree with that. Whats a realistic value for 9 recurring? If we had to many 9's then we would never get to the next decimal place. There must be a limit on this! We have a tendancy to Fit Numbers to real problems and say Math is the Universal Language, but maybe us fitting the Numbers is the problem? I dont think the problem I have posted can be realistically solved, ony circumvented. Only with an Inaccurate result! Elegantly Fudging the Result! – Rusty Nail Feb 23 '16 at 20:26
  • @Chris what is 9 recurring? I don't think I understand your problem. In any case this is not the right place to discuss the philosophy of mathematics. – Joni Feb 23 '16 at 20:28
  • @Joni - see my Question for the explanation. Besides, you asked, I only provided thoughts on the problem you bought forward. – Rusty Nail Feb 23 '16 at 20:32