//C# Floating Point Notation - Single Double Decimal Alfanumerieke en Numerieke Datatypes public class Example1 { void Main() { float[] units; float amount = 0.06D; Console.Write((amount + " : ")); int index; for (; (amount > 0); ) { for (; ((amount - this.units(index)) >= 0); ) { Console.Write((this.units(index) + " ")); amount = this.units(index); } this.index += new System.EventHandler(1); } Console.WriteLine(); Console.ReadLine(); } } public class Example2 { void Main() { Console.WriteLine(((2D % 0.2D) == 0)); Console.WriteLine((2D % 0.2D)); float someSingle = 4.99D; Console.WriteLine(((someSingle * 17) == 84.83D)); Console.WriteLine((someSingle * 17)); someSingle = (1 / 107D); Console.WriteLine(((someSingle * 107) == 1)); Console.WriteLine((someSingle * 107)); Console.ReadLine(); } } public class Example3 { public virtual void Main() { Console.WriteLine("seeeeeeeemmmmmmmmmmmmmmmmmmmmmmm"); Console.WriteLine(((this.GetBinary(1.175494E-38F) + " : ") + 1.175494E-38F.ToString())); Console.WriteLine(((this.GetBinary(0.5F) + " : ") + 0.5F.ToString())); Console.WriteLine(((this.GetBinary(0.6F) + " : ") + 0.6F.ToString())); Console.WriteLine(((this.GetBinary(float.MaxValue) + " : ") + System.Single.MaxValue.ToString())); Console.WriteLine(((this.GetBinary(-1.175494E-38F) + " : ") + (0 - 1.175494E-38F.ToString()))); Console.WriteLine(((this.GetBinary(float.MinValue) + " : ") + System.Single.MinValue.ToString())); Console.WriteLine(((this.GetBinary(0F) + " : ") + 0F.ToString())); Console.WriteLine(((this.GetBinary(0F) + " : ") + (0 - 0F.ToString()))); Console.WriteLine(((this.GetBinary(float.Epsilon) + " : ") + System.Single.Epsilon.ToString())); Console.WriteLine(((this.GetBinary(-1.401298E-45F) + " : ") + (0 - 1.401298E-45F.ToString()))); Console.WriteLine(((this.GetBinary(float.PositiveInfinity) + " : ") + System.Single.PositiveInfinity.ToString())); Console.WriteLine(((this.GetBinary(float.NegativeInfinity) + " : ") + System.Single.NegativeInfinity.ToString())); Console.ReadLine(); } public virtual void GetBinary(byte value) { GetBinary = (((value % 2)).ToString() + GetBinary); value = 1; } public virtual void GetBinary(float value) { if (BitConverter.IsLittleEndian) { for (System.Collections.IEnumerator _it1 = BitConverter.GetBytes(value).GetEnumerator(); _it1.MoveNext(); ) { byte byteElement = ((byte)(_it1.Current)); GetBinary = (this.GetBinary(byteElement) + GetBinary); } } else { throw new ApplicationException("Only Little Endian supported."); } } } public class Example4 { void Main() { float[] singleOperands; string[] operatorSymbols; for (System.Collections.IEnumerator _it1 = operatorSymbols.GetEnumerator(); _it1.MoveNext(); ) { string operatorSymbol = ((string)(_it1.Current)); Console.WriteLine(("OPERATOR " + operatorSymbol.ToString())); Console.WriteLine(); for (System.Collections.IEnumerator _it2 = singleOperands.GetEnumerator(); _it2.MoveNext(); ) { float singleOperand1 = ((float)(_it2.Current)); for (System.Collections.IEnumerator _it3 = singleOperands.GetEnumerator(); _it3.MoveNext(); ) { float singleOperand2 = ((float)(_it3.Current)); this.PrintCalculation(singleOperand1, operatorSymbol, singleOperand2); } Console.WriteLine(); } Console.WriteLine(); } Console.ReadLine(); } void PrintCalculation(float operand1, string operatorSymbol, float operand2) { Console.Write((((((this.GetString(operand1) + " ") + operatorSymbol) + " ") + this.GetString(operand2)) + " = ")); object _switch1 = operatorSymbol; if (_switch1.Equals("*")) { Console.WriteLine(this.GetString((operand1 * operand2))); } else { if (_switch1.Equals("/")) { Console.WriteLine(this.GetString((operand1 / operand2))); } else { if (_switch1.Equals("+")) { Console.WriteLine(this.GetString((operand1 + operand2))); } else { if (_switch1.Equals("-")) { Console.WriteLine(this.GetString((operand1 - operand2))); } } } } } void GetString(float value) { if (this.IsPositiveZero(value)) { GetString = "+0"; } else { GetString = value.ToString(); } } public virtual void IsPositiveZero(float value) { if (((((BitConverter.GetBytes(value).(0) == 0) && (BitConverter.GetBytes(value).(1) == 0)) && (BitConverter.GetBytes(value).(2) == 0)) && (BitConverter.GetBytes(value).(3) == 0))) { IsPositiveZero = true; } } public virtual void IsNegativeZero(float value) { if (((((BitConverter.GetBytes(value).(0) == 0) && (BitConverter.GetBytes(value).(1) == 0)) && (BitConverter.GetBytes(value).(2) == 0)) && (BitConverter.GetBytes(value).(3) == 128))) { IsNegativeZero = true; } } } //Bezoek www.vbvoorbeelden.be voor meer C# voorbeelden. //Copyright - De Wolf / vbvoorbeelden - 2003-2011 - Alle rechten voorbehouden.