www.digitalmars.com [Home] [Search] [D]

Last update Apr 4, 2002


Properties

Every type and expression has properties that can be queried:
	int.size	// yields
	float.nan	// yields the floating point value
	(float).nan	// yields the floating point nan value
	(3).size	// yields 4 (because 3 is an int)
	2.size		// syntax error, since "2." is a floating point number
	int.init	// default initializer for int's
	

Properties for Integral Data Types

	.init		initializer (0)
	.size		size in bytes
	.max		maximum value
	.min		minimum value
	.sign		should we do this?
	

Properties for Floating Point Types

	.init		initializer (NaN)
	.size		size in bytes
	.infinity	infinity value
	.nan		NaN value
	.sign		1 if -, 0 if +
	.isnan		1 if nan, 0 if not
	.isinfinite	1 if +-infinity, 0 if not
	.isnormal	1 if not nan or infinity, 0 if
	.digits		number of digits of precision
	.epsilon	smallest increment
	.mantissa	number of bits in mantissa
	.maxExp	maximum exponent as power of 2 (?)
	.max		largest representable value that's not infinity
	.min		smallest representable value that's not 0
	

.init Property

.init produces a constant expression that is the default initializer. If applied to a type, it is the default initializer for that type. If applied to a variable or field, it is the default initializer for that variable or field. For example:

	int a;
	int b = 1;
	typedef int t = 2;
	t c;
	t d = cast(t)3;

	int.init	// is 0
	a.init		// is 0
	b.init		// is 1
	t.init		// is 2
	c.init		// is 2
	d.init		// is 3

	struct Foo
	{
	    int a;
	    int b = 7;
	}
 
	Foo.a.init	// is 0
	Foo.b.init	// is 7
	

Copyright (c) 1999-2001 by Digital Mars, All Rights Reserved