Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Edited by NavBot

...

Code Block
bgColor#FFCCCC
double currentBalance; // User's cash balance 

void doDeposit(String userInput){
  double val;
  try {
    val = Double.valueOf(userInput);
  }
  catch(NumberFormatException e) {
    // Handle input format error
  }

  if(val >>= Double.MAX_VALUE - currentBalance) {
    // Handle range error
  }

  currentBalance += val;
}

...

Code Block
bgColor#ccccff
double currentBalance; // User's cash balance 

void doDeposit(String s){
  double val;
  try {
    val = Double.valueOf(userInput);
  }
  catch(NumberFormatException e) {
    // Handle input format error
  }

  if (Double.isInfinite(val)){
    // Handle infinity error 
  }

  if (Double.isNaN(val)) {
    // Handle NaN error 
  }

  if(val >>= Double.MAX_VALUE - currentBalance) {
    // Handle range error
  }
  currentBalance += val;
}

...

Wiki Markup
\[[IEEE 754|https://www.securecoding.cert.org/confluence/display/seccode/AA.+C+References#AA.CReferences-IEEE7542006|IEEE 754]\]
\[[IEEE 1003.1, 2004|https://www.securecoding.cert.org/confluence/display/seccode/AA.+C+References#AA.CReferences-IEEE1003|IEEE 1003.1, 2004]\] 

...

FLP03-J. Use the strictfp modifier for floating point calculation consistency            07. Floating Point (FLP)            FLP30-J. Do not use floating point variables as loop counters