\documentclass[]{article}
\usepackage{amsmath,graphicx,supertabular,hyperref,tabularx,ifthen}
\title{TIP \#472: Add Support for 0d Radix Prefix to Integer Literals}
\date{May 25, 2017}
\author{Venkat Iyer, Brian Griffin}
\urlstyle{sf}
\setlength{\parskip}{1ex}
\setlength{\parindent}{0pt}
\def\tipversion$#1${\texttt{\$#1\$}}
\def\tiplangle#1{\ensuremath{<}}
\def\tiprangle#1{\ensuremath{>}}
\def\tipbar#1{\ensuremath{|}}
\def\tipmail#1#2{\(\langle\){\small\expandafter\url{#1@#2}}\(\rangle\)}
\ifx\pdfoutput\undefined
\newcommand{\tipimage}[2]{\typeout{Make sure you download #1.eps}\ifthenelse{\lengthtest{0.8\textwidth>#2}\and\lengthtest{0pt<#2}}{\includegraphics{#1.eps}}{\includegraphics[width=0.8\textwidth]{#1.eps}}}
\newcommand{\tipxref}[1]{}
\newcommand{\tipxrefend}{}
\else
\newcommand{\tipimage}[2]{\typeout{Make sure you create #1.pdf}\ifthenelse{\lengthtest{0.8\textwidth>#2}\and\lengthtest{0pt<#2}}{\includegraphics{#1.pdf}}{\includegraphics[width=0.8\textwidth]{#1.pdf}}}
\pdfcatalog{/PageMode /UseOutlines}
\newcommand{\tipxref}[1]{\pdfannotlink attr {/C [0.5 0.5 1.0] /Border [0 0 1]} goto name {#1}}
\newcommand{\tipxrefend}{\pdfendlink}
\fi
\newenvironment{tipabstract}{\begin{abstract}}{\end{abstract}}
\begin{document}\maketitle
\begin{center}\begin{tabularx}{\linewidth}{|r@{: }X|}\hline
\textbf{TIP \#472}&\textbf{Add Support for 0d Radix Prefix to Integer Literals}\\\hline
Author&

Venkat Iyer \tipmail{venksi}{gmail.com}
\par
Brian Griffin \tipmail{brian_griffin}{mentor.com}
\\
Created&Thursday, \(\text{25}^{\text{th}}\) May 2017\\
Type&Project\\
Tcl Version&\(8.7\)\\
State&Accepted\\
Vote&Done\\
Version&\tipversion$Revision: 1.8 $\\
Post History&\\
\hline\end{tabularx}\end{center}
\thispagestyle{empty}\pagestyle{empty}
\begin{tipabstract}

This TIP proposes adding support for a \textbf{0d} decimal radix prefix to complement the existing \textbf{0x} hexidecimal, \textbf{0o} octal and \textbf{0b} binary radix prefixes.
\end{tipabstract}
\tableofcontents\setcounter{page}{0}\clearpage\pagestyle{plain}

\section{Rationale}

Verilog (and other Hardware Description Languages) always (or at least since the 1995 LRM) had a way to specify a decimal number explicitly. Verilog uses \textbf{'d343534} to mean decimal, VHDL actually allows any radix from 2 to 16 using syntax, so you could explicitly force a decimal interpretation using \textbf{10\#343534\#}.

Tcl now allows \textbf{0b} for binary in \textbf{expr} and \textbf{format}, which is similar to \textbf{'b} in Verilog. And of course the \textbf{0x} prefix has always been around. Another use case would be to prevent false parsing of leading zeroes in \textbf{clock format}s as octal, without having to go through a \textbf{scan}.

But a more elegant reason is that it makes the radix definition consistent, so
\begin{enumerate}
\item{}
all valid input radixes have a consistent unambiguous input literal format, and
\setcounter{enumi}{1}
\item{}
the \textbf{d} in \textbf{format \%d} finally finds its complement in \textbf{scan}.
\end{enumerate}

\section{Specification}

Extend the \textbf{TclParseNumber} function to recognize the prefixes \textbf{0d} and \textbf{0D} as decimal integers. It will have the same semantics as \textbf{0x}, but base 10 instead of base 16. 

Also extend format command '\#' flag to produce the appropriate ``0d'' for the ``\%\#d'' conversion. 

\section{Examples}

It's an integer:
\begingroup\small\begin{verbatim}
   % expr {0d12 + 0d15}
   27
   % format "%#x" 0d1024
   0x400
   % format "%#d" 128
   0d128
\end{verbatim}
\endgroup

Errors same as other radix prefixes:
\begingroup\small\begin{verbatim}
   % expr { 0d317g }
   invalid bareword "0d317g"
   in expression " 0d317g ";
   should be "$0d317g" or "{0d317g}" or "0d317g(...)" or ...
   % expr { 0x1.53 }
   missing operator at _@_
   in expression " 0x1_@_.53 "
   % expr {0d7.23}
   missing operator at _@_
   in expression "0d7_@_.23"
\end{verbatim}
\endgroup

\section{Compatibility}

Currently, literals beginning with \textbf{0d} and parsed as a number will produce an error. Any code expecting such an error would fail to produce an error an thus have a change in behavior. I would expect this situation to be uncommon.

\section{Implementation}

An implementation can be found the fossil on the ``bsg-0d-radix-prefix'' branch, including \%\#d conversion support.

\section{Copyright}

This document has been placed in the public domain.

\section{Colophon}

\textit{TIP AutoGenerator --- written by Donal K. Fellows}
\end{document}
