1 // Some types which are floating-point types. 2 static assert( isFloatingPoint!float); 3 static assert( isFloatingPoint!double); 4 static assert( isFloatingPoint!real); 5 6 static assert( isFloatingPoint!(const float)); 7 static assert( isFloatingPoint!(immutable float)); 8 static assert( isFloatingPoint!(inout double)); 9 static assert( isFloatingPoint!(shared double)); 10 static assert( isFloatingPoint!(const shared real)); 11 12 static assert( isFloatingPoint!(typeof(42.0))); 13 static assert( isFloatingPoint!(typeof(42f))); 14 static assert( isFloatingPoint!(typeof(1e5))); 15 static assert( isFloatingPoint!(typeof(97.4L))); 16 17 double d; 18 static assert( isFloatingPoint!(typeof(d))); 19 20 // Some types which aren't floating-point types. 21 static assert(!isFloatingPoint!bool); 22 static assert(!isFloatingPoint!char); 23 static assert(!isFloatingPoint!dchar); 24 static assert(!isFloatingPoint!int); 25 static assert(!isFloatingPoint!long); 26 static assert(!isFloatingPoint!(float[])); 27 static assert(!isFloatingPoint!(double[4])); 28 static assert(!isFloatingPoint!(real*)); 29 static assert(!isFloatingPoint!string); 30 31 static struct S 32 { 33 double d; 34 } 35 static assert(!isFloatingPoint!S); 36 37 // The struct itself isn't considered a floating-point type, 38 // but its member variable is when checked directly. 39 static assert( isFloatingPoint!(typeof(S.d))); 40 41 enum E : double 42 { 43 a = 12.34 44 } 45 46 // Enums do not count. 47 static assert(!isFloatingPoint!E); 48 49 static struct AliasThis 50 { 51 double d; 52 alias this = d; 53 } 54 55 // Other implicit conversions do not count. 56 static assert(!isFloatingPoint!AliasThis);
Whether the given type is one of the built-in floating-point types, ignoring all qualifiers.
Note that this does not include implicit conversions or enum types. The type itself must be one of the built-in floating-point types.
This trait does have some similarities with __traits(isFloating, T), but isFloating accepts more types than isFloatingPoint does. isFloatingPoint is specifically for testing for the built-in floating-point types, whereas isFloating tests for a whole set of types that are vaguely float-like (including enums with a base type which is a floating-point type and some of the vector types from core.simd). So, for most code, isFloatingPoint is going to be more appropriate, but obviously, it depends on what the code is trying to do.
See also: __traits(isFloating, T) isInteger isSignedInteger isNumeric isUnsignedInteger