* 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 */
| 4792 | * case of error |
| 4793 | */ |
| 4794 | static int |
| 4795 | xmlSchemaCompareFloats(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); |
no test coverage detected