Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// <summary>
- /// This code illustrates a problem when executing Queue<float>.Dequeue() when run on the
- /// default MonoForAndroid API-10 simulator configured by Xamarin Studio.
- ///
- /// The value dequeue should be 1.0f, but upon inspection it is 0.
- ///
- /// This occurs on my Android device as well (a brand new, but super cheap androd 2.3 phone)
- /// </summary>
- using System;
- using Android.App;
- using Android.Content;
- using Android.Runtime;
- using Android.Views;
- using Android.Widget;
- using Android.OS;
- using System.Diagnostics;
- using System.Collections;
- using System.Collections.Generic;
- using System.Runtime.Remoting.Metadata.W3cXsd2001;
- namespace FloatCorruption
- {
- public class CorruptedFloatException : Exception
- {
- }
- [Activity (Label = "FloatCorruption", MainLauncher = true)]
- public class Activity1 : Activity
- {
- Queue<float> _EvilFloat = new Queue<float>();
- Queue _NonGeneric = new Queue();
- Queue<double> _GenericDouble = new Queue<double>();
- protected override void OnCreate (Bundle bundle)
- {
- base.OnCreate (bundle);
- // Set our view from the "main" layout resource
- SetContentView (new View(this));
- // ok with non generic
- _NonGeneric.Enqueue(1f);
- if((float)_NonGeneric.Dequeue() != 1.0f)
- throw new CorruptedFloatException();
- _GenericDouble.Enqueue(1f);
- if(_GenericDouble.Dequeue() != 1.0)
- throw new CorruptedFloatException();
- // broken with float
- _EvilFloat.Enqueue(1f);
- var result = _EvilFloat.Dequeue();
- var result_raw = new SoapHexBinary(BitConverter.GetBytes(result)).ToString();
- Console.WriteLine("result = {0}, as hex = {1}", result, result_raw);
- if(result != 1.0f)
- throw new CorruptedFloatException();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement