The OpenD Programming Language

octal

The octal facility provides a means to declare a number in base 8. Using octal!177 or octal!"177" for 127 represented in octal (same as 0177 in C).

The rules for strings are the usual for literals: If it can fit in an int, it is an int. Otherwise, it is a long. But, if the user specifically asks for a long with the L suffix, always give the long. Give an unsigned iff it is asked for with the U or u suffix. _Octals created from integers preserve the type of the passed-in integral.

  1. template octal(string num)
    template octal (
    string num
    ) if (
    isOctalLiteral(num)
    ) {
    static if((octalFitsInInt!num && !literalIsLong!num) && !literalIsUnsigned!num)
    enum octal;
    static if(!((octalFitsInInt!num && !literalIsLong!num) && !literalIsUnsigned!num))
    static if((!octalFitsInInt!num || literalIsLong!num) && !literalIsUnsigned!num)
    enum octal;
    static if(!((octalFitsInInt!num && !literalIsLong!num) && !literalIsUnsigned!num))
    static if(!((!octalFitsInInt!num || literalIsLong!num) && !literalIsUnsigned!num))
    static if((octalFitsInInt!num && !literalIsLong!num) && literalIsUnsigned!num)
    enum octal;
    static if(!((octalFitsInInt!num && !literalIsLong!num) && !literalIsUnsigned!num))
    static if(!((!octalFitsInInt!num || literalIsLong!num) && !literalIsUnsigned!num))
    static if(!((octalFitsInInt!num && !literalIsLong!num) && literalIsUnsigned!num))
    static if((!octalFitsInInt!(num) || literalIsLong!(num)) && literalIsUnsigned!(num))
    enum octal;
    }
  2. template octal(alias decimalInteger)

Examples

// Same as 0177
auto a = octal!177;
// octal is a compile-time device
enum b = octal!160;
// Create an unsigned octal
auto c = octal!"1_000_000u";
// Leading zeros are allowed when converting from a string
auto d = octal!"0001_200_000";

See Also

parse for parsing octal strings at runtime.

Meta