[N
S S N
_Create_Label_LOOP][S S S N
_Push_0][S N
S _Duplicate][T N
T S _Read_STDIN_as_character][T T T _Retrieve][S N
S _Duplicate][S S S T S T T S T N
_Push_45_-][T S S T _Subtract][N
T S N
_If_0_jump_to_Label_LOOP][T N
S S _Print_as_character][N
S N
N
_Jump_to_Label_LOOP]
Letters S
(space), T
(tab), and N
(new-line) added as highlighting only.
[..._some_action]
added as explanation only.
Try it online (with raw spaces, tabs and new-lines only).
Explanation in pseudo-code:
Start LOOP:
Character c = STDIN as character
if(c == '-')
Go to next iteration of LOOP
Print c
Go to next iteration of LOOP
Old 48 bytes answer:
[S S S N
_Push_0][S N
S _Duplicate][T N
T T _Read_STDIN_as_integer][T T T _Retrieve][S N
S _Duplicate][N
T T S N
_If_negative_jump_to_Label_NEG][N
S N
N
_Jump_to_Label_PRINT][N
S S S N
_Create_Label_NEG][S S T T N
_Push_-1][T S S N
_Multiply][N
S S N
_Create_Label_PRINT][T N
S T _Print_as_integer]
Letters S
(space), T
(tab), and N
(new-line) added as highlighting only.
[..._some_action]
added as explanation only.
Try it online (with raw spaces, tabs and new-lines only).
Explanation in pseudo-code:
Integer i = STDIN as integer
if(i is negative)
i = i * -1
Jump to function PRINT
else
Jump to function PRINT
function PRINT:
Print i as integer to STDOUT
abs(i)
is the shortest, and for those languages that requireMath.abs(i)
like Java, .NET, JS, etc.i<0?-i:i
is the shortest. \$\endgroup\$abs
. Not a tips question to see if there is anything shorter thani<0?-i:i
as alternative? \$\endgroup\$abs
, without usingabs
ori<0?-i:i
\$\endgroup\$