Is it possible to have neg_float typespec?

Background

I am doing a small function that takes a few parameters. One such parameter is a float() that must be <= 0.

Now, if this was an integer I would simply use neg_integer() from the typespecs.

However, I am using a float() instead. Unfortunately there is no neg_float() typespec that I could find.

Question

Is there a possible way of having a neg_float() typespec, that would only accept float <= 0 ?

The short answer: no, there is not.

float is the most concrete representation of a float value in typespecs.

Integers not only have pos_*, non_neg_* and neg_* subsets, but also integers as well as integer ranges are allowed as literal values within typespecs. Given the latter having access to the former makes sense. Literal float values are also not supported for float values though.

1 Like