Can the remainder/modulus operator be used with floating point operands?
The % operator, called the modulus or remainder operator, returns the remainder of two numbers. In C and C++, the remainder operator accepts only integral operands, but in the Java programming language, it also accepts floating-point operands. Remeber that the evaluation of a floating-point remainder operator % never throws a run-time exception, even if the right-hand operand is zero. Overflow, underflow, or loss of precision cannot occur. Examples:
5.0%3.0 produces 2.0
5.0%(-3.0) produces 2.0
(-5.0)%3.0 produces -2.0
(-5.0)%(-3.0) produces -2.0
5.0/0.0 produces NaN
For the detail information, please visit 15.17.3 Remainder Operator % in Java Language Specification.
Most Viewed java Faqs
- How to use HttpURLConnection POST data to web server?(14988)
- What is runtime polymorphism in Java?(9463)
- What is String literal pool?(8786)
- Can the run() method be called directly to start a thread?(8234)
- How to add BASIC Authentication into HttpURLConnection?(7469)
- Can transient variables be declared as 'final' or 'static'?(6298)
- Can static methods be overridden?(4958)
Most Recent java Faqs
- What is the difference between an enum type and java.lang.Enum?
- Which replace function works with regex?
- Why does TreeSet.add throw ClassCastException?
- What is variable hiding and shadowing?
- Can private method be overridden?
- How to enable JDBC tracing?
- How to Retrieve Automatically Generated Keys in JDBC?