MCPcopy Create free account
hub / github.com/Kitware/VTK / xmlSchemaCompareFloats

Function xmlSchemaCompareFloats

ThirdParty/libxml2/vtklibxml2/xmlschemastypes.c:4794–4855  ·  view source on GitHub ↗

* xmlSchemaCompareFloats: * @x: a first float or double value * @y: a second float or double value * * Compare 2 values * * Returns -1 if x < y, 0 if x == y, 1 if x > y, 2 if x <> y, and -2 in * case of error */

Source from the content-addressed store, hash-verified

4792 * case of error
4793 */
4794static int
4795xmlSchemaCompareFloats(xmlSchemaValPtr x, xmlSchemaValPtr y) {
4796 double d1, d2;
4797
4798 if ((x == NULL) || (y == NULL))
4799 return(-2);
4800
4801 /*
4802 * Cast everything to doubles.
4803 */
4804 if (x->type == XML_SCHEMAS_DOUBLE)
4805 d1 = x->value.d;
4806 else if (x->type == XML_SCHEMAS_FLOAT)
4807 d1 = x->value.f;
4808 else
4809 return(-2);
4810
4811 if (y->type == XML_SCHEMAS_DOUBLE)
4812 d2 = y->value.d;
4813 else if (y->type == XML_SCHEMAS_FLOAT)
4814 d2 = y->value.f;
4815 else
4816 return(-2);
4817
4818 /*
4819 * Check for special cases.
4820 */
4821 if (xmlXPathIsNaN(d1)) {
4822 if (xmlXPathIsNaN(d2))
4823 return(0);
4824 return(1);
4825 }
4826 if (xmlXPathIsNaN(d2))
4827 return(-1);
4828 if (d1 == xmlXPathPINF) {
4829 if (d2 == xmlXPathPINF)
4830 return(0);
4831 return(1);
4832 }
4833 if (d2 == xmlXPathPINF)
4834 return(-1);
4835 if (d1 == xmlXPathNINF) {
4836 if (d2 == xmlXPathNINF)
4837 return(0);
4838 return(-1);
4839 }
4840 if (d2 == xmlXPathNINF)
4841 return(1);
4842
4843 /*
4844 * basic tests, the last one we should have equality, but
4845 * portability is more important than speed and handling
4846 * NaN or Inf in a portable way is always a challenge, so ...
4847 */
4848 if (d1 < d2)
4849 return(-1);
4850 if (d1 > d2)
4851 return(1);

Callers 1

Calls 1

xmlXPathIsNaNFunction · 0.85

Tested by

no test coverage detected