g | x | w | all
Bytes Lang Time Link
002UiuaSBCS240916T175040ZEurope20
008Wolfram Language Mathematica190918T002044Zatt
013sed220812T024144ZJiří
nan230115T194556ZThe Thon
005Knight220813T084235ZAiden Ch
003Ly220813T062609Zcnamejj
011Alice220812T013237ZBubbler
015Alice220811T235925ZJulian
005dc220811T220802ZBenji
002Vyxal210502T235617ZAaroneou
038SNOBOL4 CSNOBOL4210502T191156ZGiuseppe
123MMIX210502T190753ZNoLonger
035MMIXAL210502T190016ZNoLonger
003APL Dyalog Unicode210326T040002ZAndrew O
nanPxem210326T022140Zuser1004
012Rattle210326T031255ZDaniel H
003Phooey210214T170844ZEasyasPi
003TIBASIC200119T115510Zabsolute
032W191208T011322Zuser8505
nan190918T125256ZChronoci
002Keg191207T205225Zlyxal
007Triangular190917T194039Zsquid
002Brachylog191012T073605ZIFcoltra
006Cascade190925T084030ZJo King
034Batch190925T031004ZΟurous
014BitCycle U190924T215419ZJo King
015BitCycle U190923T075957ZDLosc
012Retina 0.8.2190917T235440ZNeil
002Stack Cats mn190921T105139ZMartin E
512Perl 5 12 Bytes190920T145229ZrpGYNay0
014Python 3190918T223116Zmypetlio
006Scala190918T150458ZSoapy
004><>190918T152025Zsteenber
004Gol><>190918T162154ZKrystosT
014R190918T051037ZNick Ken
007BrainFlak190917T221836ZRiley
005Backhand190918T070313ZJo King
002Gaia190917T193955ZGiuseppe
023Lua190918T192606Zval - di
004Runic Enchantments190918T173117ZDraco18s
029C++ gcc190917T204634ZNishioka
003x86 machine code190918T182956ZCody Gra
006Perl 5 p190918T050705ZNahuel F
012Haskell190918T161717Znimi
003Japt190918T121238ZOliver
005Cubix190918T143250ZNitrodon
039Turing Machine Language190918T115903Zouflak
023R190918T130413ZAaron Ha
003APL Dyalog Unicode190917T202236ZJ. Sall&
023C clang190918T115253ZAZTECCO
022MarioLANG190918T093435ZDorian
004MathGolf190918T084211ZKevin Cr
048Whitespace190918T083248ZKevin Cr
020PHP190918T065724ZNight2
718Ruby p190918T065503ZG B
022Python 3190918T051337ZNick Ken
003J190918T014836ZJonah
002Klein190917T212251ZWheat Wi
008Haskell190918T003511ZØrj
003Perl 6 / Raku190917T224231Zuser0721
002Stax190917T213106ZOliver
006Befunge98 FBBI190917T211534Zovs
006Labyrinth / Hexagony190917T204901ZJonathan
011JavaScript190917T204257ZShaggy
002Jelly190917T204000ZJonathan
00205AB1E190917T194815Zjasanbor
014PowerShell190917T194435ZVeskah
005V vim190917T194512ZDJMcMayh
003Japt190917T194111ZShaggy

UiuaSBCS, 2 bytes

Try it in both directions!

Do I even have to explain?

Wolfram Language (Mathematica), 9 8 bytes

suniM@@D

Try it online!

Sometimes the world is a boring place.

Forward: suniM@@D=D

Backward: D@@Minus=Minus

sed, 14 13 bytes

Thanks to Philippos for -1 byte.

##--#s;#-#^#s

The code is only comment, which means the input is outputted unchanged.

Attempt This Online!

Reversed:

s#^#-#;s#--##

The code first append - in front of the string. Then if there are two minuses they get removed.

Attempt This Online!

Thunno, \$ 2 \log_{256}(96) \approx \$ 1.65 bytes

nI

Attempt This Online! or !enilnO sihT tpmettA

Outputs inside brackets, e.g. [5].

Port of jasanborn's 05AB1E answer. n = negate, I = push input.

Knight, 5 bytes

O P~O

Try It Online!

Try It Online reversed!

Ly, 3 bytes

+0-

Try it online!

Forwards:

+    : compute "0 + STDIN"
 0   : push 0
  -  : subtract the top two stack entries
     : prints stack as a number automatically

Backwards:

-    : compute "0 - STDIN"
 0   : push 0
  +  : add the top two stack entries
     : prints stack as a number automatically

Alice, 11 bytes

\ X'@
/I-O/

Try it online!

!enilno ti yrT

Operates entirely within ordinal mode. The negation is done by taking string symmetric difference X with the single-char string "-". The code path IXO is common; when reversed, '- is also stepped, pushing "-" before the input.

Alice, 15 bytes

/O\ /I@
@I/R\O/

Try it online!
!enilno ti yrT

Flattened

Original I O@, reads from the input, output
Reversed IRO@, reads from the input, negate, output

The mirrors switches in and out of ordinal mode, which execute the code in diagonal

dc, 5 bytes

dp-r0

Try it online!

Vyxal, 2 bytes

#N

Try it Online!

!enilnO ti yrT

#N is a comment, so nothing happens and the input is outputted unchanged.

N# negates the input, which is then outputted implicitly.

If you’re not a fan of using comments for something like this, the # can be replaced with any of ? , ₴ ⁰, etc.

SNOBOL4 (CSNOBOL4), 38 bytes

	OUTPUT =INPUT;END;DNE;TUPIN-= TUPTUO	

Try it online!

Reversed

Anything after an END label is ignored. ; is an alternate newline delimiter which made this answer easier to think about.

MMIX, 12 bytes (3 instrs)

00000000: f8010000 000001f8 00000036           ẏ¢¡¡¡¡¢ẏ¡¡¡6

Disassembled:

f   POP  1,0
    TRAP 0,Fopen,248
    TRAP 0,Halt,36

Reversed and disassembled:

f   NEGU $0,0,$0
    POP  1,0
    TRAP 0,Fopen,248

This is essentially the same as my MMIXAL answer, except that that relied on comments and reversed the source code, while this just relies on early return.

MMIXAL, 35 bytes

f POP 1,0 # 0,1 POP ;0$,0,0$ UGEN f

Very simple; when reversed, is just negate-and-return.

APL (Dyalog Unicode), 3 bytes

-/⊢
-/ ⍝ Summation with alternating sign
  ⊢ ⍝ Identity function

Reversed

⊢/-
⊢/ ⍝ Reduce (fold) with the Right operator
  - ⍝ Negate

Mirrored

⊣\-
⊣ ⍝ Left
 \ ⍝ Expand
  - ⍝ Negate

Try it online!

Pxem, Filename: 30 27 bytes + Content: 0 bytes = 30 27 bytes, does not support signed zero, not clean.

Try it online!

!enilno ti yrT

With comments

Original

XX.z
.a._.nXX.z # push getint; putint pop
.a.o.-XX.z # DOTo and DOT- works like EOF for insufficient items
.aa.dXX.z # push ascii code of a; exit
.a.n.-.-.00y.\001c._.XX.z # deadcode
  ## NOTE this is syntaxically valid
.a

Reversed

XX.z
.a._.cXX.z # push getint; dup
.a\001.yXX.z # push 1; while pop>pop; do
  .a00.-.-XX.z # (*essentially*) push abs(0-pop)
    # NOTE actually: push 48; push 48; 
    #     push abs(pop-pop); push abs(pop-pop)
    # NOTE NULL char not supported for filename
  .a.n.dXX.z # putint pop; exit
.a.aXX.z # done
.a-.o.nXX.z # push hyphen; putchar pop; putint pop
.a._XX.z # this is why it aborts when only an integer is given
.a..c.sXX.z # push dot
.a

Pxem, Filename: 34 bytes + Content: 0 bytes = 34 bytes, clean.

This version deals with exiting; reversed version exits well against non-negative input, too.

Try it online!

Rattle, 12 bytes

||1c0gI|\\&-

Try it online!

!enilno ti yrT

This takes advantage of how Rattle is parsed. As of right now, there is only support for one input section (everything before the first |) - this means that anything after any following |'s will be disregarded. This more or less splits the code into two sections:

|

This is the effective forward code, which is the cat program.

-&\\|Ig0c1

This is the reverse code, which spits out the negative of the input. There's still possibility that this could be golfed further!

Phooey, 3 bytes

+.-

Try it online! (Forwards)

Try it online! (Backwards)

This assumes an empty stack and an empty tape.

Explanation:

Each instruction in Phooey has a modifier:

So, when read forwards, it is this:

+.-
+.  # Add to the tape
  - # pop and subtract (does nothing because stack is empty)

And backwards, it is the same for -.


Phooey, universal, 5 bytes

;0@.&

This version works regardless of the stack and tape state, and also preserves the stack contents.

Forwards:

;0@.&
;0    # tape = 0 - tape (don't care)
  @.  # read input and push to stack
    & # pop from the stack to the tape

Try it online! (Forwards)

Backwards:

&.@0;
&.    # read int and store to tape
  @0  # push 0 to the stack
    ; # pop, tape is 0 (stack) - tape

Try it online! (Backwards)

TI-BASIC, 3 bytes

Ans-0

Very simple and works the same way as the top J answer.

Input is an integer in Ans.

Examples:

4:Ans-0
              4
4:0-Ans
             -4

W, 3 2 bytes

Pretty much a port of the Keg answer. Might get around to implement an implicit return.

%_

Explanation

   % Since there is nothing on-stack, return the input.
%_ % Start a comment

noitanalpxE

_  % Negate input & return
 % % Start a comment

Excel VBA, 12

?[A1]']1A[-?

Reversed:

?-[A1]']1A[?

Input is cell A1 of the ActiveSheet. Comments still work in the Immediate Window :)

Keg, 2 bytes

Try it online! !enilno ti yrT

Real simple. When run in normal direction, it simply prints the input. When run in reverse direction (±#), it negates the input.

Triangular, 8 7 bytes

$%%.|.$

Try it online!

Ungolfed:

   $           | $: Read an Integer
  % %          | %: Output it
 . | .
$

Reversed:

$.|.%%$

Try it online!

Previous Version (8 bytes):

$.%..|.$

Brachylog, 2 bytes

&ṅ

Brachylog implicitly inputs from the left and outputs from the right.
& ignores anything to the left and passes the input to the function rightwards.
constrains each side of it to be negated versions of each other.

Try it online

Cascade, 6 bytes

# -
&#

Try it online!

and reversed:

#&
- #

Try it online!

I think this is the optimal answer for this question. In order to negate the input, we have to use the - operator, which means the code must be at least three wide so the left and the right operands aren't the same. It must then be two tall to have not loop infinitely. That means at least one row must be three wide, and the other has to be two wide, since if it was one wide, it must be the redirect to the #, which would have to be directly under it. Feel free to prove me wrong though.

Explanation:

For the initial program, we only execute # (integer output) on & (integer input). Basically, the only instructions that matter are:

#
&

For the reversed program, the # on the second line leads to - (left minus right). This wraps around the program, with the right being the &, and the left as an empty space, which is zero. This results in 0 - input, which is the negated input.

Batch, 34 bytes

@ECHO.%1 2>MER@
@REM>2 1%=-aa/TES@

Echoes (ECHO.) the input (%1). The rest of the first line technically redirects STDERR to a file called MER@, but this isn't impactful.
Second line is commented out (REM...).

Reversed

@SET/aa-=%1 2>MER@
@REM>2 1%.OHCE@

Uses the arithmetic mode of the set command (SET /a) to subtract (-=) the input (%1) from an undefined variable (a) which is equivalent to 0 - input. Again, the rest of the first line technically redirects STDERR to a file called MER@, but this isn't impactful.
Second line is commented out (REM...).

BitCycle -U, 14 bytes

<  ^
v/?!
+~ +

Try it online!

And reversed

+ ~+
!?/v
^  <

Try it online!

The -U flag translates input/output to signed Unary, i.e. unary 1s with a zero in front if the number is negative. The first program just pipes input (?) to the output (!) directly right of it.

The reverse instead takes only the first bit of the number with the / command and dupnegs (~). If it is a 1 then it sends 0 left and 1 right, where the +s redirect them to join the flow to the output. If the first bit is 0 instead, the 0 goes right and the 1 goes left, and the + redirect them away from the output. All in all, this has the behaviour of stripping a leading zero if the input has one, otherwise prepending a zero if it doesn't, which means inverting the sign of the input.

BitCycle -U, 15 bytes

First, a word about the -U flag. Internally, BitCycle only deals in 1's and 0's, so to allow working with decimal integers, it has flags to convert decimal input to unary. In particular, -U allows for signed integers by adding a 0 to the front of any nonpositive integer's unary representation: 4 is 1111, -4 is 01111, and 0 is 0. The same transformation is applied in reverse to the output, with the convenient addition that empty output is treated as 0.

Forward

^> 

?!+?
 <0/ 

Try it online!

The leftmost ? gets the input, which goes straight into the ! to be output unchanged.

Reverse

 /0< 
?+!?

 >^

Try it online!

The leftmost ? gets the input. The + sends the leading 0 bit, if any, left (north), and the 1 bits right (south).

If there is a leading 0 bit, it hits the splitter / and turns east, deactivating the splitter. The < sends it west again, through the deactivated splitter and off the playfield. The 0 bit that started on the playfield also hits the < and goes through the deactivated splitter and off the playfield. Meanwhile, the 1 bits are directed around by the > and ^ and reach the !, where they are output.

If there is no leading 0 bit, the 0 bit that starts on the playfield hits the < and goes west to the splitter /. Since the splitter has not been deactivated, it directs the bit south, and the + sends it west into the output !. Meanwhile, the 1 bits are directed to the output, with enough delay to make sure they get there after the 0 bit.

TL;DR: Nonpositive inputs have their leading 0 bit stripped and their magnitude is output. Positive inputs have a leading 0 bit added and are thus output as negative numbers of the same magnitude.

Retina 0.8.2, 13 12 bytes

-*$1#$
)^(|-

Try it online! It's impossible for the first line to match anything, so nothing happens. In reverse:

-|(^)
$#1$*-

Try it online! Explanation: Either a leading (implicitly) - or a leading empty string is matched. This is replaced with - repeated according to the number of empty strings that were matched.

Edit: Saved 1 byte thanks to @MartinEnder (although, cunningly, the reversed original worked with floating-point numbers in scientific notation). As he points out, Retina 1 would be a further byte shorter as its syntax for * is slightly different and does not require the adjacent $ (and it would therefore also modify illegal inputs such as -1# which this version ignores).

Stack Cats -mn, 2 bytes

-X

Try it online!

Try the reverse!

Explanation

Turns out this is actually a lot easier than the previous challenge in Stack Cats. The full program (after applying -m) here is -X-. X is used to swap the stacks left and right of the tape head, i.e. it doesn't affect the initial stack at all, so we can ignore it. But then the program is effectively just -- (negate the top of the stack twice), which does nothing.

For the inverse program, applying -m gives X-X. Again, X does nothing, so the program is effectively just -, which negates the top of the stack.

The only other 2-byte solution is -=, but it's virtually the same. The only difference is that = swaps only the tops of the adjacent stacks, not the entire stacks.

But again, using -m feels a bit like cheating, so below is a solution that uses a fully mirrored program.


Stack Cats -n, 7 bytes

:I<->I:

Try it online!

Try the reverse!

Explanation

The considerations from the previous answer still apply: any valid solution needs to use the paired characters and I. The six possible solutions (included in the TIO link) are all virtually the same. - and _ are equivalent in this program, and : can be replaced by | or T (which do the same for non-zero inputs and coincidentally also work for zero inputs). I've just picked this one to explain because it's easiest.

So remember that the initial stack holds the input on top of a -1 (on top of infinitely many zeros) whereas all the other stacks along the tape only hold zeros. Stack Cats also has the property that any even-length program does nothing (provided it terminates, but we can't use loops for this challenge anyway). The same is then obviously true for any odd-length program whose centre character does nothing... let's see:

:    Swap the input with the -1 below.
I    Move the -1 one stack to the left and turn it into +1.
<    Move another stack left (without taking the value).
-    Negate the zero on top of that stack (i.e. do nothing).

Therefore, the second half of the program exactly undoes the first half and we end up with the input on top of a -1 again.

The inverse program is :I>-<I:. Let's see how that changes things:

:    Swap the input with the -1 below.
I    Move the -1 one stack to the left and turn it into +1.
>    Move one stack right, i.e. back onto the initial stack which still holds the input.
-    Negate the input.
<    Move back to the left where we've parked the 1.
I    Move that 1 back onto the initial stack and turn it back into a -1.
:    Swap the -1 below the negated input to act as an EOF marker.

Perl 5 - 12 Bytes

say$_#_$-yas

Reversed

say-$_#_$yas

Abides by the -0 rule.

Does require the -nE flags on execution.

Python 3, 22 14 bytes

int#__bus__. 0

Try it online!

Uses the int class's constructor and a built-in pseudo-private method.

Scala, 6 bytes

+_//_-

Try it online!

Unfortunately a function can't just contain a _ to return the first argument, but using unary_+ will return the value unchanged.

Once flipped, the code is -_ which does a unary_- on the first argument, which flips the sign.

><>, 5 4 bytes

n-r0

uses stack initialisation with the -v option, put your input variable there.

Try it online!

Or try the reversal

Explanation

n       Prints whatever is on the stack as a number
 -      Subtract the top 2 elements on the stack.
        There aren't 2 elements, so it crashes.
  r0    Never gets executed

or reversed:

0       Push a 0 onto the stack
 r      reverse the stack (now 0, -v)
  -     Subtract top 2 elements and push result (0-v, ie negated)
   n    Print as number
        The code wraps around and executes again. 
        It crashes on the - as there is only one
        item on the stack: 0.

Gol><>, 4 bytes

Ih-I

One byte golfed off courtesy of JoKing

Try it online!

R, 14 bytes

scan()#)(nacs-

Try it online!

A full program that reads a number, or reads and negates a number. The reverse functionality is protected by an inline comment

Brain-Flak, 7 bytes

#)]}{[(

Try it online!

Reversed:

([{}])#

Try it online!

Note: Only works in interpreters that support comments (e.g. works in Rain-Flak, but not in BrainHack)


If we also swap opening/closing brackets instead of just reversing the bytes we can do this in 8 bytes without using comments:

({}[{}])

Try it online!
Try it reversed!

Backhand, 6 5 bytes

I@-Ov

Try it online! Try it doubled!

Made a little complex due to the nature of the pointer in Backhand. I don't think it's possible to get any shorter haha, turns out I was wrong. This duplicates no instruction and reuses both the input, output and terminate commands between the two programs. Now I think it is optimal, since you need all of the IO-@ commands to work, and in a 4 byte program you can only execute two of those commands.

Explanation:

The pointer in Backhand moves at three cells a tick and bounces off the boundaries of the cell, which means the general logic is overlapping. However you can manipulate this speed with the v and ^ commands.

The original program executes the instructions IO-@, which is input as number, output as number, subtract, terminate. Obviously the subtract is superfluous. In the code these are:

I@-Ov
^  ^    Reflect
  ^     Reflect again
 ^

The reversed program executes v-I-vO-@. The v reduces the pointer steps between ticks, and the - subtracts from the bottom of the stack, which is implicitly zero. The extra - commands do nothing. The program executes like

vO-@I
v       Reduce pointer speed to 2
  -     Subtract zero from zero
    I   Get input as number and reflect off boundary
  -     Subtract input from zero
v       Reduce pointer speed to 1
 O      Output as number
  -     Subtract zero from zero
   @    Terminate

Gaia, 2 bytes

_@

Try it online!

_	| implicit push input and negate
 @	| push next input OR push last input (when all inputs have been pushed)
	| implicit print TOS

Reversed:

@	| push input
 _	| negate
	| implicit print TOS

Lua, 23 bytes

print(...)--)...-(tnirp

Try it online!

Comment abuse all over again.

Runic Enchantments, 4 bytes

i@Zi

Try it online! Try it reversed!

Its the answer I originally wrote on the other challenge when I misread the description.

C++ (gcc), 29 bytes

#define f(x)x//x-)x(g enifed#

Try it online!

Fixed issue brought up by @Nick Kennedy

x86 machine code, 3 bytes

C3 D8 F7

The above bytes of code define a function that is a no-op: it simply returns control to the caller. That function is followed by two garbage bytes that will not be executed, since they come after a return—they are in "no man's land". In assembler mnemonics:

ret                     ; C3    
fdiv  st(0), st(7)      ; D8 F7

Okay, so now some troll comes by and reverses the order of the bytes:

F7 D8 C3

These bytes now define a function that takes an integer argument in the EAX register, negates it, and returns control to the caller. In assembler mnemonics:

neg  eax     ; F7 D8
ret          ; C3

So…that was simple. :-)

Note that we can make the "negation" instruction be anything we want, since it is never executed in the "forward" orientation and only executed in the "reversed" orientation. Therefore, we can follow the same pattern to do arbitrarily more complicated stuff. For example, here we take an integer argument in a different register (say, EDI, to follow the System V calling convention commonly used on *nix systems), negate it, and return it in the conventional EAX register:

C3      ret
D8 F7   fdiv  st(0), st(7)      ;  \ garbage bytes that
F8      clc                     ;  | never get executed,
89      .byte 0x89              ;  / so nobody cares

  ↓ ↓

89 F8   mov  eax, edi
F7 D8   neg  eax
C3      ret

Perl 5 (-p), 7 6 bytes

-1 thanks to @primo

$_*=$#

TIO

A comment doesn't change input

#1-=*_$

Negate the input

$_*=-1#

TIO

Haskell, 12 bytes

f=id;x-0=x f

Try it online! Reverse:

f x=0-x;di=f

Try it online!

Not as short as Ørjan Johansen's answer, but without comments.

Japt, 3 bytes

n U

Try it

Try it reversed

3 bytes

nÎN

Try it

Try it reversed

Cubix, 5 bytes

@IO\n

Try it online!

Try it reversed!

Turing Machine Language, 39 bytes

The Positive

1 r - _ 0
0 l * * 0
0 - _ l 0
0 _ _ r 0

The Negative

0 r _ _ 0
0 l _ - 0
0 * * l 0
0 _ - r 1

This one was a bit trickier than I thought, mostly because I had to get past my prejudices of having code that runs with 'compile' errors.

R, 23 bytes

I decided to give it a go without the comment trick.

Forward

`+`=scan;""+-0;nacs=`+`

Try it online!

Reverse

`+`=scan;0-+"";nacs=`+`

Try it online!

In the forward version + is acting a binary operator, and - is a unary operator.

In the reverse the + becomes unary and the - is binary. So scan function takes the arguments: file="" which means stdin and what=0, which are also defaults. So when the + is unary the first argument is on the right, when it is binary the first argument is on the left.

The

;nacs=`+`

part of the code does nothing really useful, so in a sense my code is not really very much more valid than using the comment trick.

APL (Dyalog Unicode), 13 3 bytes

-∘0

Try it online!

Trivial answer. Returns arg or ¯arg.

Saved 10 bytes by not being dumb (thanks Adám).

Altered the resulting 3-byter to a more fitting function.

C (clang), 23 bytes

f(*x){}//};x*-=x*{)x*(g

Try it online!

MarioLANG, 22 bytes

;:
=#
:)!
--
<(
"
[>
;

Try it online!

He just inputs and outputs the number before he falls to EOF

reversed:

;
>[
"
(<
--
!):
#=
:;

Try it online!

He loops until the input value is 0 and the output value is -input, the he says the number.

MathGolf, 4 bytes

*b╘k

Try it online or try it online reversed.

Explanation:

Regular:

*     # Multiply the (implicit) input with the (implicit) input
      #  STACK: [input**2]
 b    # Push -1
      #  STACK [input**2, -1]
  ╘   # Discard everything on the stack
      #  STACK: []
   k  # Push the input as integer
      #  STACK: [input]
      # (output the entire stack joined together as result)

Reversed:

k     # Push the input as integer
      #  STACK: [input]
 ╘    # Discard everything on the stack
      #  STACK: []
  b   # Push -1
      #  STACK: [-1]
   *  # Multiple the (implicit) input with this -1
      #  STACK: [-input]
      # (output the entire stack joined together as result)

And to answer your question: no, MathGolf does not have a 1-byte negate for integers. There is ~ for -n-1, but unfortunately nothing for -n (so *b could alternatively be )~ for the same byte-count).

Whitespace, 48 bytes

S S S N
S N
S T N
T   T   T   T   T   T   N
S T N
N
N
T   S N
T   N
S S T   N
T   T   S S T   T   T   T   T   N
T   S N
S N
S S S 

Letters S (space), T (tab), and N (new-line) added as highlighting only.

Minor modification of my Whitespace answer for the I reverse the source code, you negate the output! challenge.

Try it online or try it online reversed (with raw spaces, tabs and new-lines only).

Explanation:

Utilizing the Exit Program builtin being a short palindrome NNN.
The regular program will:

SSSN   # Push 0 to the stack
SNS    # Duplicate it
TNTT   # Read STDIN as integer, and store it at heap address 0
TTT    # Retrieve the input from heap address 0, and push it to the stack
TNST   # Pop and print the top of the stack as number
NNN    # Exit the program, making everything after it no-ops

The reverse program will:

SSSN   # Push 0 to the stack
SNS    # Duplicate it
TNTT   # Read STDIN as integer, and store it at heap address 0
TTT    # Retrieve the input from heap address 0, and push it to the stack
SSTTN  # Push -1 to the stack
TSSN   # Multiply the top two values on the stack together
TNST   # Pop and print the top of the stack as number
NNN    # Exit the program, making everything after it no-ops

Small additional explanation of pushing a number:

I.e. SSTTSTSN pushes -10. For the 0 we don't need an explicit S=0, so simply SSSN or SSTN is enough.

PHP, 20 bytes

<?=$argn;#;ngra$-=?<

Try it online!

Ruby -p , 7+1 = 8 bytes

#-?<<>$

Try it online!

Reverse:

Try it online!

Python 3, 22 bytes

lambda x:x#x-:x adbmal

Try it online!

A lambda which implements the identity function (or negation)

J, 3 bytes

-&0

Try it online!

-&0 is "argument minus 0"

0&- is "0 minus argument"

Klein, 2 bytes

Works in all 12 topologies!

@-

Try it online!

Reverse

-@

Try it online!

- negates the input and @ ends the program

Haskell, 8 bytes

Anonymous identity function, turning into subtraction from 0 when reversed.

id--)-0(

Try it online!

Reversed:

(0-)--di

Try it online!

Perl 6 / Raku, 3 bytes

*-0

Try it online!

Creates a Whatever code block. Read in normally its standard block equivalent is -> \x {x - 0}, but in reverse it becomes -> \x {0 - x}.

Stax, 2 bytes

pN

Run and debug it

Befunge-98 (FBBI), 6 bytes

&.@.-&

Try it online! Try it reversed!

Labyrinth / Hexagony, 6 bytes

Labyrinth:

?!@!`?

Try it online! and its reverse.

Hexagony:

?!@!~?

Try it online! and its reverse.

How?

?       - take a signed integer
(` / ~) - negate
!       - output top-of-stack / current-memory-edge
@       - exit

JavaScript, 11 bytes

n=>n//n->=n

Try it Online! | Reversed

Jelly, 2 bytes

oN

Try it online! and its reverse.

oN - (input) OR ((input) negated)

No - ((input) negated) OR (input)

05AB1E, 2 bytes

(I

Try it online!

Reversed

(    negates nothing
  I  pushes input

I    pushes input
  (  negates input

PowerShell, 18 14 bytes

$args#"sgra$"-

Try it online! !enilno ti yrT

First of the trivial comment-abuse answers

V (vim), 5 bytes

É-ó--

Try it online!

Hexdump:

00000000: c92d f32d 2d                             .-.--

Japt, 3 bytes

TnU

Try it | Reversed

Same method as my earlier solution, with T being 0 and U being the input.