private void ValidateFloat(JsonSchemaModel schema)
{
if (schema == null)
{
return;
}
if (!TestType(schema, JsonSchemaType.Float))
{
return;
}
ValidateNotDisallowed(schema);
double value = Convert.ToDouble(_reader.Value, CultureInfo.InvariantCulture);
if (schema.Maximum != null)
{
if (value > schema.Maximum)
{
RaiseError("Float {0} exceeds maximum value of {1}.".FormatWith(CultureInfo.InvariantCulture, JsonConvert.ToString(value), schema.Maximum), schema);
}
if (schema.ExclusiveMaximum && value == schema.Maximum)
{
RaiseError("Float {0} equals maximum value of {1} and exclusive maximum is true.".FormatWith(CultureInfo.InvariantCulture, JsonConvert.ToString(value), schema.Maximum), schema);
}
}
if (schema.Minimum != null)
{
if (value < schema.Minimum)
{
RaiseError("Float {0} is less than minimum value of {1}.".FormatWith(CultureInfo.InvariantCulture, JsonConvert.ToString(value), schema.Minimum), schema);
}
if (schema.ExclusiveMinimum && value == schema.Minimum)
{
RaiseError("Float {0} equals minimum value of {1} and exclusive minimum is true.".FormatWith(CultureInfo.InvariantCulture, JsonConvert.ToString(value), schema.Minimum), schema);
}
}
if (schema.DivisibleBy != null)
{
double remainder = FloatingPointRemainder(value, schema.DivisibleBy.GetValueOrDefault());
if (!IsZero(remainder))
{
RaiseError("Float {0} is not evenly divisible by {1}.".FormatWith(CultureInfo.InvariantCulture, JsonConvert.ToString(value), schema.DivisibleBy), schema);
}
}
}