- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Single.IsInfinity() Method in C# with Example
The Single.IsInfinity() method in C# is used to return a value indicating whether the specified number evaluates to negative or positive infinity.
Syntax
The syntax is as follows −
public static bool IsInfinity (float val);
Above, val is a single-precision floating-point number.
Example
Let us now see an example −
using System; public class Demo { public static void Main(){ float f1 = 19.3f; float f2 = Single.MaxValue; Console.WriteLine("Value1 = "+f1); Console.WriteLine("Hashcode for Value1 = "+f1.GetHashCode()); Console.WriteLine("TypeCode for Value1 = "+f1.GetTypeCode()); Console.WriteLine("Is Value1 value is positive or negative infinity? = "+Single.IsInfinity(f1)); Console.WriteLine("
Value2 = "+f2); Console.WriteLine("Hashcode for Value2 = "+f2.GetHashCode()); Console.WriteLine("TypeCode for Value2 = "+f2.GetTypeCode()); Console.WriteLine("Is Value2 value is positive or negative infinity? = "+Single.IsInfinity(f2)); } }
Output
This will produce the following output −
Value1 = 19.3 Hashcode for Value1 = 1100637798 TypeCode for Value1 = Single Is Value1 value is positive or negative infinity? = False Value2 = 3.402823E+38 Hashcode for Value2 = 2139095039 TypeCode for Value2 = Single Is Value2 value is positive or negative infinity? = False
Example
Let us now see another example −
using System; public class Demo { public static void Main(){ float f1 = 5.0f/0.0f; float f2 = Single.MinValue; Console.WriteLine("Value1 = "+f1); Console.WriteLine("Hashcode for Value1 = "+f1.GetHashCode()); Console.WriteLine("TypeCode for Value1 = "+f1.GetTypeCode()); Console.WriteLine("Is Value1 value is positive or negative infinity? = "+Single.IsInfinity(f1)); Console.WriteLine("
Value2 = "+f2); Console.WriteLine("Hashcode for Value2 = "+f2.GetHashCode()); Console.WriteLine("TypeCode for Value2 = "+f2.GetTypeCode()); Console.WriteLine("Is Value2 value is positive or negative infinity? = "+Single.IsInfinity(f2)); } }
Output
This will produce the following output −
Value1 = ∞ Hashcode for Value1 = 2139095040 TypeCode for Value1 = Single Is Value1 value is positive or negative infinity? = True Value2 = -3.402823E+38 Hashcode for Value2 = -8388609 TypeCode for Value2 = Single Is Value2 value is positive or negative infinity? = False
Advertisements