Daumantas Versockas
Daumantas Versockas

Reputation: 777

iOS Objective-C float ranges

I have a question about CGRect ranges

I need to save huge numbers in CGRect. I have a float declaration:

float xLowerValue = ((self.bounds.size.width - lowerHandleWidth) * (_lowerValue - _minimumValue) / (_maximumValue - _minimumValue))+(lowerHandleWidth/2.0f);

Its values are:

2015-05-21 17:10:01.967 ILG-Scouting Munster[5751:184222] self.bounds.size.width = 300;
2015-05-21 17:10:01.967 ILG-Scouting Munster[5751:184222] lowerHandleWidth = 0;
2015-05-21 17:10:01.968 ILG-Scouting Munster[5751:184222] _lowerValue = 100;
2015-05-21 17:10:01.968 ILG-Scouting Munster[5751:184222] _minimumValue = 4.547124e+08;
2015-05-21 17:10:01.968 ILG-Scouting Munster[5751:184222] _maximumValue = 4.547124e+08;

With these values I get xLowerValue value equal to -Inf

How can I avoid this?

Upvotes: 0

Views: 328

Answers (2)

rmaddy
rmaddy

Reputation: 318794

Your min and max values are the same therefore you end up dividing by zero. Dividing by 0 gives the result of Inf (Infinity).

Fix the problem by properly initializing your _minimumValue and _maximumValue so they have proper and different values.

Upvotes: 1

Quentin Hayot
Quentin Hayot

Reputation: 7876

  1. Make sure you never divide by zero
  2. According to this page, the values are like below:

enter image description here

Upvotes: 2

Related Questions