Possible reasons are caching, naming or forcing type
Caching (not applicable)
You want to avoid the cost of creating an object during the act of comparison. In Java an example would be
BigDecimal zero = new BigDecimal ("0.0");
this involves a fairly heavy creation process and is better served using the provided static method:
BigDecimal zero = BigDecimal.ZERO;
This allows comparisons without incurring a repeated cost of creation since the BigDecimal is pre-cached by the JVM during initialisation.
In the case of what you have described, a primitive is performing the same job. This is largely redundant in terms of caching and performance.
Naming (unlikely)
The original developer is attempting to provide a uniform naming convention for common values throughout the system. This has some merit, especially with uncommon values but something as basic as zero is only worth it in the case of the caching case earlier.
Forcing type (most likely)
The original developer is attempting to force a particular primitive type to ensure that comparisons are cast to their correct type and possibly to a particular scale (number of decimal places). This is OK, but the simple name "zero" is probably insufficient detail for this use case with ZERO_1DP being a more appropriate expression of the intent.
x
has typefloat
, thenx > 0.0
forces promotion todouble
, which might be less efficient. That's not a good reason for using a named constant though, just for making sure your constants have the correct type (e.g.0f
,float(0)
ordecltype(x)(0)
).13.37
isn'tfloat
, it'sdouble
. So if you wanted afloat
then it's conceivable your tutor was correct. In some contexts (e.g. assignment to a float)13.37
will be implicitly converted to thefloat
that you wanted, and in other contexts (e.g. template type deduction) it won't be, whereas thestatic const float
always starts as the type you intended. Hence, more type-safe. Mind you, so would be13.37f
! There are other reasons for avoiding the macro than "type-safety", though, so it's just as likely the tutor was giving you a poor argument.