In the language dc
, the -
character is reserved strictly for subtraction, so it cannot be used to enter a negative number. An alternative format for entering negative numbers was created: precede the number with an underscore, as in _5
. Many challenges require submissions to accept negative input.
This may be a trivial question, but I want to know whether dc
is allowed to take negative input with underscores rather than minuses. As an example, in my submission for the challenge Calculate the sum of ILD, I left a buffer of numbers waiting on the stack to receive a leading -
and report back whether the number was negative. Instead, I'd prefer to just assume that the number will be input as negative in the manner recognised by the interpreter. (I don't intend to change that particular submission; I'm just asking for future reference.)
_
as the minus sign of literals. In general I'd say that you should be able to work with your language's native formats unless the challenge says otherwise. (This is really the same as reading lists as[1,2]
,(1 2)
or{1,2}
depending on your language's syntax.) \$\endgroup\$_
for negative numbers, and APL uses¯
. \$\endgroup\$