Floating Point Comparison C++ - Finding maximum -


When I compare floating point, I get printed inf in the output screen Can help?

  unsigned longer temporarily; Long double tempDec = 0.0, max = 0.0; Unsigned long maxInd = 0, j = 0; (Unsigned for long I = 1; i & lt; 100; i ++) for {j = i-1; Temporary = 0; While (h> gt; 0) {if (returnGCD (j, i) == 1) {temp ++; } J--; } TempDec = ((long dual) i) / ((double long) temporary); If (tempDec> max) {max = tempDec; maxInd = I; }} Cout & lt; & Lt; Max. & Lt; & Lt; "#" & lt; & Lt; Maximum end lieutenant; & Lt; Endl;   

When I tried to exclude this snippet, I would like the output

  inf # 1   

I do not know what's wrong with this. For only one comparison, we can use fibers (), is there any other special way to find out more numbers in the float?

The loop has its first recurrence, temp = 0 , j = 0 create tempDec due to division by 0. if (tempDec> max) will be true for the first time and max From that onwards, if will always be false.

Fix the code so that you do not divide by 0.

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -