code: double cosine(SparseVector vec1, SparseVector vec2)
      {
          double norm1 = vec1.norm();
          double norm2 = vec2.norm();
          double result = 0.0f;
          if (norm1 == 0 && norm2 == 0)
          {
              return result;
          }
          else
          {
              double prod = inner_product(vec1, vec2);
              result = prod / (norm1 * norm2);
              return Double.isNaN(result) ? 0.0f : result;
          }
      }
docs: Calculate the cosine value between vectors.