-1

Preface this with I am a data analyst who works primarily in SQL and some Python. My Java knowledge is from a single semester in Uni a decade ago. I have been tasked with updating a process that has largely been untouched since it was written in 2002. It used some very convoluted SQL to pull from source DB, probably written by a java person, and then several java functions to manipulate the data to the desired report outcome.

I have worked through 3 of the five functions and recreated/refined the process, but am stuck on several things.

This code here:

public void calculateCorrectionFactor(int roundingSecs)
throws CtFatalException
{
  if (roundingSecs < 1)
  {
     throw new CtFatalException("roundingSecs must be > 0");
  }

  double sign = 1d;

  if (this.modalDriftSecs < 0)
  {
     sign = -1d;
  }

  double dividend = this.modalDriftSecs*sign/roundingSecs;

  String str = Double.toString(dividend+0.5d);

  int indexOfDecimal = str.indexOf('.');

  String intStr = str.substring(0,indexOfDecimal);

  int parsedInt = Integer.parseInt(intStr);

  Double doubleSign = new Double(sign);

  this.calculatedCorrectionFactor = doubleSign.intValue()*parsedInt*roundingSecs ;}

The gist I understand is this calculation modalDriftSecs*sign/roundingSecs is the main output, but what is the -1d and 1d for sign? A double is purely numerical, isn't it?

  • 1
    Does this answer your question? [Why is there a "d" in the definition of Double.NaN = 0.0d / 0.0?](https://stackoverflow.com/questions/41283474/why-is-there-a-d-in-the-definition-of-double-nan-0-0d-0-0) – Rohde Fischer Apr 23 '20 at 13:08

1 Answers1

1

'd' is suffix for double, similarly 'f' denotes float. So, 1d is equivalent to 1.000...., 4d is 4.0000..... -1d is -1.0000...