Bug 25170 - Floating point division error
Summary: Floating point division error
Status: RESOLVED INVALID
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: XI 8.4.0
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2014-12-09 00:43 UTC by Joseph Hanna
Modified: 2016-03-02 00:07 UTC (History)
4 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED INVALID

Description Joseph Hanna 2014-12-09 00:43:28 UTC
Description of Problem:

I am getting an exception in my production application on iPad 2 devices but not in iPad Air (both iOS 8.1) for a MT.D table.

Here is the code on row tap:

    var t = root.TableView;
    RectangleF r = t.RectForRowAtIndexPath(t.IndexPathForSelectedRow);

    Debug.WriteLine(string.Format("Tap x:y  {0}", r.ToString()));
    //iPad 2 Returns:    Tap x:y  {X=0,Y=10037,Width=350,Height=63}
    //iPad Air returns:  

    //THIS FOLLOWING LINE CRASHES.  Divide by "2" should produce "int" result
    float yPos = r.Y + float.Parse(int.Parse((r.Height / 2).ToString()).ToString());


This is the exception:

System.FormatException: Input string was not in the correct format
  at System.Int32.Parse (System.String s) [0x00010] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System/Int32.cs:624 



Steps to reproduce the problem:
1. Run the above code



Actual Results:

This code has been in production for nearly two years.  Only recent release to App Store crashes - on iPad 2 only.


Expected Results:


How often does this happen? 

Every time


Additional Information:

=== Xamarin Studio ===

Version 5.5.4 (build 15)
Installation UUID: 91c8007d-5c08-419d-8255-8baafc57debc
Runtime:
	Mono 3.10.0 ((detached/92c4884)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 310000031

=== Apple Developer Tools ===

Xcode 6.1.1 (6611)
Build 6A2008a

=== Xamarin.Mac ===

Version: 1.10.0.18 (Business Edition)

=== Xamarin.iOS ===

Version: 8.4.0.43 (Business Edition)
Hash: 840a925
Branch: 
Build date: 2014-11-16 21:03:22-0500

=== Xamarin.Android ===

Version: 4.20.0.28 (Business Edition)
Android SDK: /Users/joe/Library/Developer/Xamarin/android-sdk-mac_x86
	Supported Android versions:
		2.1   (API level 7)
		2.2   (API level 8)
		2.3   (API level 10)
		3.1   (API level 12)
		4.0   (API level 14)
		4.0.3 (API level 15)
Java SDK: /usr
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-466.1-11M4716)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-466.1, mixed mode)

=== Build Information ===

Release ID: 505040015
Git revision: f93940a35458a18052f1a25e106e62ca970d9c40
Build date: 2014-11-19 15:32:41-05
Xamarin addins: dc23cbd91a3a0e1d326328e1229e86c942a49ec8

=== Operating System ===

Mac OS X 10.10.1
Darwin Josephs-MacBook-Pro.local 14.0.0 Darwin Kernel Version 14.0.0
    Fri Sep 19 00:26:44 PDT 2014
    root:xnu-2782.1.97~2/RELEASE_X86_64 x86_64
Comment 1 Rolf Bjarne Kvinge [MSFT] 2014-12-11 02:24:54 UTC
Height = 63 / 2 => 31.5, so your conclusion that that divide by 2 should provide an int result is not correct for this case.

That said, exactly what is the purpose of converting to strings and the parsing?
Comment 2 Joseph Hanna 2016-03-02 00:07:15 UTC
Forget this. Refactored code I want to get it off my list