[Question]
  [
Given a number N, output the [sign](https://en.wikipedia.org/wiki/Sign_function) of N:
* If N is positive, output 1
* If N is negative, output -1
* If N is 0, output 0
N will be an integer within the representable range of integers in your chosen language.
## The Catalogue
The Stack Snippet at the bottom of this post generates the catalogue from the answers a) as a list of shortest solution per language and b) as an overall leaderboard.
To make sure that your answer shows up, please start your answer with a headline, using the following Markdown template:
```
## Language Name, N bytes
```
where `N` is the size of your submission. If you improve your score, you *can* keep old scores in the headline, by striking them through. For instance:
```
## Ruby, <s>104</s> <s>101</s> 96 bytes
```
If there you want to include multiple numbers in your header (e.g. because your score is the sum of two files or you want to list interpreter flag penalties separately), make sure that the actual score is the *last* number in the header:
```
## Perl, 43 + 2 (-p flag) = 45 bytes
```
You can also make the language name a link which will then show up in the snippet:
```
## [><>](https://esolangs.org/wiki/Fish), 121 bytes
```
```
/* Configuration */
var QUESTION_ID = 103822; // Obtain this from the url
// It will be like https://XYZ.stackexchange.com/questions/QUESTION_ID/... on any question page
var ANSWER_FILTER = "!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe";
var COMMENT_FILTER = "!)Q2B_A2kjfAiU78X(md6BoYk";
var OVERRIDE_USER = 8478; // This should be the user ID of the challenge author.
/* App */
var answers = [], answers_hash, answer_ids, answer_page = 1, more_answers = true, comment_page;
function answersUrl(index) {
  return "https://api.stackexchange.com/2.2/questions/" +  QUESTION_ID + "/answers?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + ANSWER_FILTER;
}
function commentUrl(index, answers) {
  return "https://api.stackexchange.com/2.2/answers/" + answers.join(';') + "/comments?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + COMMENT_FILTER;
}
function getAnswers() {
  jQuery.ajax({
    url: answersUrl(answer_page++),
    method: "get",
    dataType: "jsonp",
    crossDomain: true,
    success: function (data) {
      answers.push.apply(answers, data.items);
      answers_hash = [];
      answer_ids = [];
      data.items.forEach(function(a) {
        a.comments = [];
        var id = +a.share_link.match(/\d+/);
        answer_ids.push(id);
        answers_hash[id] = a;
      });
      if (!data.has_more) more_answers = false;
      comment_page = 1;
      getComments();
    }
  });
}
function getComments() {
  jQuery.ajax({
    url: commentUrl(comment_page++, answer_ids),
    method: "get",
    dataType: "jsonp",
    crossDomain: true,
    success: function (data) {
      data.items.forEach(function(c) {
        if (c.owner.user_id === OVERRIDE_USER)
          answers_hash[c.post_id].comments.push(c);
      });
      if (data.has_more) getComments();
      else if (more_answers) getAnswers();
      else process();
    }
  });  
}
getAnswers();
var SCORE_REG = /<h\d>\s*([^\n,<]*(?:<(?:[^\n>]*>[^\n<]*<\/[^\n>]*>)[^\n,<]*)*),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/;
var OVERRIDE_REG = /^Override\s*header:\s*/i;
function getAuthorName(a) {
  return a.owner.display_name;
}
function process() {
  var valid = [];
  
  answers.forEach(function(a) {
    var body = a.body;
    a.comments.forEach(function(c) {
      if(OVERRIDE_REG.test(c.body))
        body = '<h1>' + c.body.replace(OVERRIDE_REG, '') + '</h1>';
    });
    
    var match = body.match(SCORE_REG);
    if (match)
      valid.push({
        user: getAuthorName(a),
        size: +match[2],
        language: match[1],
        link: a.share_link,
      });
    else console.log(body);
  });
  
  valid.sort(function (a, b) {
    var aB = a.size,
        bB = b.size;
    return aB - bB
  });
  var languages = {};
  var place = 1;
  var lastSize = null;
  var lastPlace = 1;
  valid.forEach(function (a) {
    if (a.size != lastSize)
      lastPlace = place;
    lastSize = a.size;
    ++place;
    
    var answer = jQuery("#answer-template").html();
    answer = answer.replace("{{PLACE}}", lastPlace + ".")
                   .replace("{{NAME}}", a.user)
                   .replace("{{LANGUAGE}}", a.language)
                   .replace("{{SIZE}}", a.size)
                   .replace("{{LINK}}", a.link);
    answer = jQuery(answer);
    jQuery("#answers").append(answer);
    var lang = a.language;
    lang = jQuery('<a>'+lang+'</a>').text();
    
    languages[lang] = languages[lang] || {lang: a.language, lang_raw: lang, user: a.user, size: a.size, link: a.link};
  });
  var langs = [];
  for (var lang in languages)
    if (languages.hasOwnProperty(lang))
      langs.push(languages[lang]);
  langs.sort(function (a, b) {
    if (a.lang_raw.toLowerCase() > b.lang_raw.toLowerCase()) return 1;
    if (a.lang_raw.toLowerCase() < b.lang_raw.toLowerCase()) return -1;
    return 0;
  });
  for (var i = 0; i < langs.length; ++i)
  {
    var language = jQuery("#language-template").html();
    var lang = langs[i];
    language = language.replace("{{LANGUAGE}}", lang.lang)
                       .replace("{{NAME}}", lang.user)
                       .replace("{{SIZE}}", lang.size)
                       .replace("{{LINK}}", lang.link);
    language = jQuery(language);
    jQuery("#languages").append(language);
  }
}
```
```
body {
  text-align: left !important;
  display: block !important;
}
#answer-list {
  padding: 10px;
  width: 290px;
  float: left;
}
#language-list {
  padding: 10px;
  width: 500px;
  float: left;
}
table thead {
  font-weight: bold;
}
table td {
  padding: 5px;
}
```
```
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.sstatic.net/Sites/codegolf/all.css?v=ffb5d0584c5f">
<div id="language-list">
  <h2>Shortest Solution by Language</h2>
  <table class="language-list">
    <thead>
      <tr><td>Language</td><td>User</td><td>Score</td></tr>
    </thead>
    <tbody id="languages">
    </tbody>
  </table>
</div>
<div id="answer-list">
  <h2>Leaderboard</h2>
  <table class="answer-list">
    <thead>
      <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr>
    </thead>
    <tbody id="answers">
    </tbody>
  </table>
</div>
<table style="display: none">
  <tbody id="answer-template">
    <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr>
  </tbody>
</table>
<table style="display: none">
  <tbody id="language-template">
    <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr>
  </tbody>
</table>
```
  
[Answer]
## [Retina](https://github.com/m-ender/retina), 9 bytes
```
[1-9].*
1
```
[Try it online!](https://tio.run/nexus/retina#DcnBCQAgDATB/5YinHiJPqxF7L@M6G9g6lj79oar5Ei00EQfgczABMlk8fsB "Retina – TIO Nexus")
Replaces a non-zero digit and everything after it with `1`. This leaves a potential leading `-` intact and changes all numbers except `0` itself to absolute value `1`.
[Answer]
# C (GCC), ~~24~~ ~~23~~ ~~22~~ 18 bytes
*Thanks to @aross and @Steadybox for saving a byte!*
```
f(n){n=!!n|n>>31;}
```
Not guaranteed to work on all systems or compilers, works on [TIO](https://tio.run/nexus/c-gcc#@5@mkadZnWerqJhXk2dnZ2xoXfs/NzEzTyNTszotv0gj01bX1DrTxsxas6AoM68kTUNJNUVBNSUmT0knU1tbJw2oThOoBQA "C (gcc) – TIO Nexus").
[Answer]
## Mathematica, 4 bytes
```
Clip
```
How about not using the built-in `Sign` and still scoring 4 bytes? ;)
`Clip` with a single argument clips (or clamps) the input value between `-1` and `1`. Since the inputs will only be integers, this is the same as using `Sign`.
[Answer]
# COW, ~~225~~ ~~213~~ 201 bytes
```
oomMOOmoOmoOmoOmoOMoOMoOmOomOomOoMoOMMMmoOMMMMOOMOomOo
mOoMOomoOmoOmoomOomOoMMMmoOmoOmoOMMMMOOOOOmoOMOoMOomOo
mOomOoMoOMMMmoOMMMMOOMOomOomOoMoOmoOmoOmoomoOmoomOomOo
mOomoomoOMOOmoOmoOmoOMOoMMMOOOmooMMMOOM
```
[Try it online!](https://tio.run/nexus/cow#hY7LDQAgCEMn8qRrNExCuv8Jtfi7mTQEmvIgSIeZ8wqSG1NzBFx1JHH8UdfKdhRbEIVNZGT4C7w/8MVOyXn/hM6Jnw0iSm0d "COW – TIO Nexus")
The way that this code works is that it determines the sign by alternating adding and subtracting bigger numbers, and seeing which one was the last one that worked. Given any non-zero integer, first subtract 1, then add 2, then subtract 3, etc. and you'll eventually reach 0. Keep track of your state by alternating adding and subtracting 2 to a value that starts off at 0. For example:
```
-5  - 1  = -6  (current state: 0 + 2 = 2)
-6  + 2  = -4  (current state: 2 - 2 = 0)
-4  - 3  = -7  (current state: 0 + 2 = 2)
-7  + 4  = -3  (current state: 2 - 2 = 0)
-3  - 5  = -8  (current state: 0 + 2 = 2)
-8  + 6  = -2  (current state: 2 - 2 = 0)
-2  - 7  = -9  (current state: 0 + 2 = 2)
-9  + 8  = -1  (current state: 2 - 2 = 0)
-1  - 9  = -10 (current state: 0 + 2 = 2)
-10 + 10 =  0  (current state: 2 - 2 = 0)
value is now at 0.  state - 1 = 0 - 1 = -1
sign of original number is -1
```
When you're done, subtract 1 from your state and you get the sign, positive or negative.
If the original number is 0, then don't bother doing any of this and just print 0.
## Detailed Explanation:
```
oom                                        ;Read an integer into [0]
MOO                                        ;Loop while [0] is non-empty
    moOmoOmoOmoOMoOMoOmOomOomOo            ;    Decrement [4] twice
    MoOMMMmoOMMM                           ;    Increment [1], then copy [1] to [2]
    MOO                                    ;    Loop while [2] is non-empty
        MOomOomOoMOomoOmoO                 ;        Decrement [0] and [2]
    moo                                    ;    End loop now that [2] is empty
    mOomOoMMMmoOmoOmoOMMM                  ;    Navigate to [0], and copy to [3]
    MOO                                    ;    Perform the next steps only if [3] is non-zero
        OOOmoOMOoMOomOomOomOoMoOMMMmoOMMM  ;        Clear [3], increment [4] twice, increment [1], and copy it to [2]
        MOO                                ;        Loop while [2] is non-empty
            MOomOomOoMoOmoOmoO             ;            Decrement [2] and increment [0]
        moo                                ;        End loop now that [2] is empty
    moO                                    ;        Navigate back to [3]
    moo                                    ;    End the condition
    mOomOomOo                              ;    Navigate back to [0]
moo                                        ;End loop once [0] is empty.
moO                                        ;Navigate to [1]. If [1] is 0, then input was 0.  Otherwise, [4] contains (sign of [0] + 1)
MOO                                        ;Perform the next steps only if [1] is non-zero
    moOmoOmoOMOoMMMOOO                     ;    Navigate to [4], copy it to the register, and clear [4].
moo                                        ;End condition
MMMOOM                                     ;If the register contains something (which is true iff the condition ran), paste it and print it.  Otherwise, no-op and print 0.
```
I'm still experimenting with golfing it (you will be shocked to discover that golfing in COW is rather difficult), so this may come down a few more bytes in the future.
[Answer]
# [Cubix](https://github.com/ETHproductions/cubix), 10 bytes
```
(W0^I?>O2@
```
[Test it online!](http://ethproductions.github.io/cubix/?code=KFcwXkk/Pk8yQA==&input=Ng==&speed=4)
This code is wrapped to the following cube net:
```
    ( W
    0 ^
I ? > O 2 @ . .
. . . . . . . .
    . .
    . .
```
The code is then run with the IP (instruction pointer) starting on the `I`, facing east. `I` inputs a signed integer from STDIN, pushing it onto the stack.
The next command is `?`, which changes the direction of the IP depending on the sign of the top item. If the input is 0, it keeps moving in same direction, running through the following code:
* `>` - Point the IP to the east. (No-op since we're already going east.)
* `O` - Output the top item as an integer.
* `2` - Push 2 to the stack. This is practically a no-op, because...
* `@` - Terminates the program.
If the input is negative, the IP turns left at the `?`; because this is a cube, the IP moves onto the `0` in the second row, heading east. `0` pushes a literal 0, then this code is run:
* `^` - Point the IP north.
* `W` - "Sidestep" the IP one spot to the left.
* `(` - Decrement the top item.
The TOS is now `-1`, and the IP wraps around the cube through a bunch of no-ops `.` until it hits the `>`. This runs the same output code mentioned above, outputting `-1`.
If the input is positive, the same thing happens as with negative inputs, with one exception: the IP turns right instead of left at the `?`, and wraps around the cube to the `2`, which pushes a literal 2. This is then decremented to 1 and sent to output.
[Answer]
# [APL (Dyalog APL)](http://dyalog.com/), 1 [byte](https://codegolf.meta.stackexchange.com/a/9429/43319)
Works for complex numbers too, returning 1∠*θ*:
```
×
```
[TryAPL online!](http://tryapl.org/?a=%u22A2N%u2190%AF1%200%201%D7%3F3/10%20%u22C4%20%D7N&run)
---
Without that built-in, for integers (as per OP):
```
¯1⌈1⌊⊢
```
`¯1⌈` the largest of negative one and
`1⌊` the smallest of one and
`⊢` the argument
[TryAPL online!](http://tryapl.org/?a=f%u2190%AF1%u23081%u230A%u22A2%20%u22C4%20%u22A2N%u2190%AF1%200%201%D7%3F3/10%20%u22C4%20f%20N&run)
... and a general one:
```
>∘0-<∘0
```
`>∘0` more-than-zero
`-` minus
`<∘0` less-than-zero
[TryAPL online!](http://tryapl.org/?a=f%u2190%3E%u22180-%3C%u22180%20%u22C4%20%u22A2N%u2190%AF1%200%201%D7%3F3/10%20%u22C4%20f%20N&run)
[Answer]
# JavaScript (ES6), 9 bytes
```
Math.sign
```
Straightforward.
The shortest non-builtin is 13 bytes:
```
n=>n>0|-(n<0)
```
Thanks to @Neil, this can be golfed by a byte, but at the cost of only working on 32-bit integers:
```
n=>n>0|n>>31
```
Or you could do
```
n=>n>0?1:!n-1
```
which seems more golfable, but I'm not sure how.
[Answer]
# Vim, 22 bytes
```
xVp:s/-/-1^M:s/[1-9]/1^M
```
Saved one byte thanks to [@DJMcMayhem](https://codegolf.stackexchange.com/users/31716/d!jmcmayhem)!
Here, `^M` is a literal newline.
As [@nmjcman101](https://codegolf.stackexchange.com/users/62346/nmjcman101) pointed out in the comments, a single regex can be used (`:s/\v(-)=[^0].*/\11^M`, 20 bytes) instead, but since this is basically the same as a Retina answer would be, I'm sticking to my own method.
Explanation:
```
xVp                        Delete everything except the first character. If the number is negative, this leaves a -, a positive leaves any number between 1 and 9, and 0 leaves 0.
   :s/-/-1^M               Replace a - with a -1
            :s/[1-9]/1^M   Replace any number between 1 and 9 with 1.
```
Here's a gif of it running with a negative number (old version):
[![Running with negative](https://i.stack.imgur.com/GULkF.gif)](https://i.stack.imgur.com/GULkF.gif)
Here's it running with 0:
[![Running with zero](https://i.stack.imgur.com/MBag5.gif)](https://i.stack.imgur.com/MBag5.gif)
Running with positive:
[![Running with positive](https://i.stack.imgur.com/TIozg.gif)](https://i.stack.imgur.com/TIozg.gif)
[Answer]
## [><>](https://esolangs.org/wiki/Fish), ~~9~~ 8 bytes
*Thanks to Sp3000 for saving a byte.*
```
'i$-%n/
```
There's an unprintable `0x01` before the `/`.
[Try it online!](https://tio.run/nexus/fish#@6@eqaKrmseo//@/oZExAA "><> – TIO Nexus")
### Explanation
This is a port of my [character code-based Labyrinth answer](https://codegolf.stackexchange.com/a/103857/8478).
```
'     Push the entire program (except ' itself) onto the stack, which ends 
      with [... 1 47].
i     Read the first character of the input.
$-    Subtract the 47.
%     Take the 1 modulo this value.
n     Output the result as an integer.
0x01  Unknown command, terminates the program.
```
[Answer]
# ///, ~~52~~ 36 bytes
```
/a/\/1\/\///2a3a4a5a6a7a8a9a10a11/1/
```
## Ungolfed, explanation:
```
/2/1/
/3/1/
/4/1/
/5/1/
/6/1/
/7/1/
/8/1/
/9/1/
/10/1/
/11/1/
```
It's basically a MapReduce implemenatation, i.e. there are two phases:
* Replace all occurrences of digits `2`-`9` by `1`, e.g. `1230405` -> `1110101`
* Reduce pairs of `11` or `10` to `1` repeatedly, e.g. `1110101`-> `1`
If there was a `-` in front initially, it will remain and the output will be `-1`. A single `0` is never replaced, thus resulting in itself.
**Update:** Save additional 16 bytes by aliasing `//1/` with `a`, thanks to Martin Ender.
[**Try it online, with test cases**](https://tio.run/nexus/slashes#DcS7EYAwFAPBXL0wsvwDenFy/RfxYIMt4@OcP7szmCw2Nw8vaSSOpfQhXXNtqVV9)
[Answer]
# [Python 2](https://docs.python.org/2/), 17 bytes
```
lambda n:cmp(n,0)
```
[Try it online!](https://tio.run/nexus/python2#S1OwVYj5n5OYm5SSqJBnlZxboJGnY6D5v6AoM69EIU3DSJMLxtRFYgNVAAA "Python 2 – TIO Nexus")
[Answer]
## [Labyrinth](https://github.com/m-ender/labyrinth), 10 bytes
```
?:+:)%:(%!
```
[Try it online!](https://tio.run/nexus/labyrinth#@29vpW2lqWqloar4/7@hkTEA "Labyrinth – TIO Nexus")
### Explanation
Labyrinth's control flow semantics actually give you a "free" way to determine a number's sign, because the chosen path at a 3-way fork depends on whether the sign is negative, zero or positive. However, I haven't been able to fit a program with junctions into less than 12 bytes so far (although it may be possible). 
Instead, here's a closed-form solution, that doesn't require any branches:
```
Code    Comment             Example -5      Example 0       Example 5
?       Read input.         [-5]            [0]             [5]
:+      Double.             [-10]           [0]             [10]
:)      Copy, increment.    [-10 -9]        [0 1]           [10 11]
%       Modulo.             [-1]            [0]             [10]
:(      Copy, decrement.    [-1 -2]         [0 -1]          [10 9]
%       Modulo.             [-1]            [0]             [1]
!       Print.              []              []              []
```
The instruction pointer then hits a dead end, turns around and terminates when `%` now attempts a division by zero.
Doubling the input is necessary to make this work with inputs `1` and `-1`, otherwise one of the two modulo operations would already attempt a division by zero.
[Answer]
# C, ~~24~~ ~~20~~ ~~19~~ 18 bytes
I abuse two C exploits to golf this down; This is in C (GCC).
```
f(a){a=a>0?:-!!a;}
```
[Try it online!](https://tio.run/nexus/c-gcc#@5@mkahZnWibaGdgb6WrqJhoXfs/M69EITcxM09Ds5pLQaGgCMhP01BSzYzJU9JJ0zDW1LTGImyGXdgAu7CuEXZxExzKDXGIQx1TlFpSWpSnYGDNVfv/a16@bnJickYqAA)
---
Revision History:
1) `f(a){return(a>0)-(a<0);}` //24 bytes
2) `f(a){a=(a>0)-(a<0);}` //20 bytes
3) `f(a){a=a>0?:-1+!a;}` //19 bytes
4) `f(a){a=a>0?:-!!a;}` //18 bytes
---
Revision 1: First attempt. Simple logic
Revision 2: Abuses a **memory/stack bug** in GCC where, as far as I can tell, a non-returning function will return the last set variable in certain cases.
Revision 3: Abuses ternary behavior where undefined result will return conditional result (which is why the *true* return on my ternary is nil)
Revision 4: Subtract a bool cast (`!!`) from the ternary conditional substitution for `nil` referenced in revision 2.
[Answer]
# [Brain-Flak](https://github.com/DJMcMayhem/Brain-Flak) ~~74 42~~ 40 Bytes
Saved 2 bytes thanks to 1000000000
```
{([({}<([()])>)]<>(())){({}())<>}}{}({})
```
[Try it Online!](http://brain-flak.tryitonline.net/#code=eyhbKHt9PChbKCldKT4pXTw-PCgoKSk-KXsoe30oKSk8Pn19e30oe30p&input=LTc)
**Explanation:**
```
{                                }       # if 0 do nothing
   (          )                          # push:                           
    {}<     >                            # the input, after 
       (    )                            # pushing:
        [  ]                             # negative:
         ()                              # 1
 (                    )                  # Then push:
  [            ]                         # the negative of the input
                <>                       # on the other stack with:
                   ()                    # a 1 
                  (  )                   # pushed under it
                       {        }        # while 1: 
                        ({}())           # increment this stack and...
                              <>         # switch stacks
                                 {}      # pop the top (the counter or 0 from input)
                                   (  )  # push:
                                    {}   # the top (this is a no-op, or pushes a 0)
```
[Answer]
# PHP, 16 bytes
Uses the new spaceship operator.
```
<?=$argv[1]<=>0;
```
[Answer]
# TI-Basic, 8 bytes
```
median({1,Ans,~1
```
Alternative solutions (feel free to suggest more):
```
max(~1,min(Ans,1               8  bytes
0:If Ans:Ans/abs(Ans           9  bytes
(Ans>0)-(Ans<0                 10 bytes
```
[Answer]
# [J](http://www.jsoftware.com/), 1 [byte](https://codegolf.meta.stackexchange.com/a/9429/43319)
```
*
```
[Try it online (with test cases)!](https://tio.run/nexus/j#@///v5aCqYKBQrwpAA)
[Answer]
## Perl, 9 bytes
**Requires `-E` at no extra cost.**
```
say<><=>0
```
### Usage
```
perl -E 'say<><=>0' <<< -9999
-1
perl -E 'say<><=>0' <<< 9999
1
perl -E 'say<><=>0' <<< -0
0
```
I'm happy with the fish operator!
[Answer]
# [Pushy](https://github.com/FTcode/Pushy), 7 bytes
This is probably the strangest-looking program I've ever written...
```
&?&|/;#
```
[**Try it online!**](https://tio.run/nexus/pushy#@69mr1ajb638//9/XUMDAA)
It uses `sign(x) = abs(x) / x`, but with an explicit `sign(0) = 0` to avoid zero division error.
```
          \ Take implicit input
&?   ;    \ If the input is True (not 0):
  &|      \  Push its absolute value
    /     \  Divide
      #   \ Output TOS (the sign)
```
This works because `x / abs(x)` is **1** when **x** is positive and **-1** when **x** is negative. If the input is 0, the program jumps to the output command.
---
### 4 bytes (non-competing)
Because of holidays and having too much time, I've done a complete rewrite of the Pushy interpreter. The above program still works, but because `0 / 0` now default to 0, the following is shorter:
```
&|/#
```
[**Try it online!**](https://tio.run/nexus/pushy#@69Wo6/8//9/XUMDAA)
[Answer]
# Ruby, 10 bytes
```
->x{x<=>0}
```
[Answer]
## [Stack Cats](https://github.com/m-ender/stackcats), 6 + 4 = 10 bytes
```
_[:I!:
```
+4 bytes for the `​ -nm` flags. `n` is for numeric I/O, and since Stack Cats requires programs to be palindromic, `m` implicitly mirrors the source code to give the original source
```
_[:I!:!I:]_
```
[Try it online!](https://tio.run/nexus/stackcats#@x8fbeWpaPX/v6GJkYWp@X/dvFwA) As with basically all good Stack Cats golfs, this was found by brute force, beat any manual attempts by a long shot, and can't easily be incorporated into a larger program.
Add a `D` flag if you'd like to see a step-by-step program trace, i.e. run with `-nmD` and check STDERR/debug.
---
Stack Cats uses a tape of stacks which are implicitly filled with zeroes at the bottom. At the start of the program, all input is pushed onto the input stack, with a `-1` at the base to separate the input from the implicit zeroes. At the end of the program, the current stack is output, except a base `-1` if present.
The relevant commands here are:
```
_           Perform subtraction [... y x] -> [... y y-x], where x is top of stack
[           Move left one stack, taking top of stack with you
]           Move right one stack, taking top of stack with you
:           Swap top two of stack
I           Perform [ if top is negative, ] if positive or don't move if zero. Then
                negate the top of stack.
!           Bitwise negate top of stack (n -> -n-1)
```
Note that all of these commands are invertible, with its inverse being the mirror of the command. This is the premise of Stack Cats — all nontrivial terminating programs are of odd length, since even length programs self-cancel.
We start with
```
               v
               n
              -1
...  0    0    0    0    0  ...
```
`_` subtracts, making the top `-1-n`, and `[` moves the result left one stack:
```
           v
       -1-n   -1
...  0    0    0    0    0  ...
```
`:` swaps top two and `I` does nothing, since the top of stack is now zero. `!` then bitwise negates the top zero into a `-1` and `:` swaps the top two back. `!` then bitwise negates the top, turning `-1-n` back into `n` again:
```
          v
          n
         -1   -1
...  0    0    0    0    0  ...
```
Now we branch based on `I`, which is applied to our original `n`:
* If `n` is negative, we move left one stack and end with `-n` on an implicit zero. `:` swaps, putting a zero on top, and `]` moves the zero on top of the `-1` we just moved off. `_` then subtracts, leaving the final stack like `[-1 -1]`, and only one `-1` is output since the base `-1` is ignored.
* If `n` is zero, we don't move and `:` swaps, putting `-1` on top. `]` then moves this left `-1` on top of the right `-1`, and `_` subtracts, leaving the final stack like `[-1 0]`, outputting the zero and ignoring the base `-1`.
* If `n` is positive, we move right one stack and end with `-n` on a `-1`. `:` swaps, putting the `-1` on top, and `]` moves this `-1` right, on top of an implicit zero. `_` then subtracts, giving `0 - (-1) = 1` and leaving the final stack like `[1]`, which is output.
[Answer]
# C#, 16 15 bytes
*Improved solution thanks to [Neil](https://codegolf.stackexchange.com/users/17602/neil)*
```
n=>n>0?1:n>>31;
```
Alternatively, the built-in [method](https://msdn.microsoft.com/en-us/library/system.math.sign(v=vs.100).aspx) is 1 byte longer:
```
n=>Math.Sign(n);
```
Full program with test cases:
```
using System;
public class P
{
    public static void Main()
    {
        Func<int,int> f =
        n=>n>0?1:n>>31;
        // test cases:
        for (int i=-5; i<= 5; i++)
            Console.WriteLine(i + " -> " + f(i));
    }
}
```
[Answer]
# [MATL](https://github.com/lmendo/MATL), 6 bytes
```
0>EGg-
```
Input may be a number or an array. The result is number or an array with the corresponding values.
[Try it online!](https://tio.run/nexus/matl#@29g5@qervv/vwUA "MATL – TIO Nexus") Or [test several cases](https://tio.run/nexus/matl#@29g5@qervv/f7SFgq6FgkEsAA) using array input.
### Explanation
This avoids using the builtin sign function (`ZS`).
```
0>   % Take input implicitly. Push 1 if positive, 0 otherwise
E    % Multiply by 2
Gg   % Push input converted to logical: 1 if nonzero, 0 otherwise
-    % Subtract. Implicitly display
```
[Answer]
# Piet, ~~188~~ ~~53~~ ~~46~~ 41 bytes
```
5bpjhbttttfttatraaearfjearoaearbcatsdcclq
```
[Online interpreter available here.](http://zobier.net/piet/)
This piet code does the standard `(n>0)-(n<0)`, as there is no sign checking builtin. In fact, there is no less-than builtin, so a more accurate description of this method would be `(n>0)-(0>n)`.
The text above represents the image. You can generate the image by pasting it into the text box on the interpreter page. For convenience I have provided the image below where the codel size is 31 pixels. The grid is there for readability and is not a part of the program. Also note that this program does not cross any white codels; follow the colored codels around the border of the image to follow the program flow.
### Explanation
[![Program](https://i.stack.imgur.com/EUvlO.png)](https://i.stack.imgur.com/EUvlO.png)
```
Instruction    Δ Hue   Δ Lightness   Stack
------------   -----   -----------   --------------------
In (Number)    4       2             n
Duplicate      4       0             n, n
Push [1]       0       1             1, n, n
Duplicate      4       0             1, 1, in, in
Subtract       1       1             0, in, in
Duplicate      4       0             0, 0, in, in
Push [4]       0       1             4, 0, 0, in, in
Push [1]       0       1             1, 4, 0, 0, in, in
Roll           4       1             0, in, in, 0
Greater        3       0             greater, in, 0
Push [3]       0       1             3, greater, in, 0
Push [1]       0       1             1, 3, greater, in, 0
Roll           4       1             in, 0, greater
Greater        3       0             less, greater
Subtract       1       1             sign
Out (Number)   5       1             [Empty]
[Exit]         [N/A]   [N/A]         [Empty]
```
To reduce the filesize any further, I would need to actually change the program *(gasp)* instead of just compressing the file as I have been doing. I would like to remove one row which would golf this down to 36. I may also develop my own interpreter which would have a much smaller input format, as actually changing the code to make it smaller is not what code golf is about.
The mods told me that the overall filesize is what counts for Piet code. As the interpreter accepts text as valid input and raw text has a much smaller byte count than any image, text is the obvious choice. I apologize for being cheeky about this but I do not make the rules. The [meta discussion](https://codegolf.meta.stackexchange.com/questions/10991/how-to-determine-the-length-of-a-piet-program) about this makes my opinions on the matter clear.
If you think that that goes against the spirit of Piet or would like to discuss this further for any reason, please check out the [discussion on meta](https://codegolf.meta.stackexchange.com/questions/10991/how-to-determine-the-length-of-a-piet-program).
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 1 [byte](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
Ṡ
```
**[TryItOnline!](http://jelly.tryitonline.net/#code=4bmg&input=&args=MA)**
The monadic sign [atom](https://github.com/DennisMitchell/jelly/wiki/Atoms), `Ṡ`, does exactly what is specified for an integer input, either as a full program or as a monadic link (function taking one argument).
[Answer]
# Mathematica, 4 bytes
```
Sign
```
Exactly what it says on the tin
[Answer]
# Octave, ~~26~~ 24 bytes
```
f=@(x)real(asin(x))/pi*2
```
This is my first [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") Octave answer, any golfing tips are appreciated!
[Try it online!](https://tio.run/nexus/octave#@59m66BRoVmUmpijkVicmQdka@oXZGoZ/U/TMDQy1uQCUiDCAEToGkJIoPh/AA "Octave – TIO Nexus")
The idea for taking the `asin` comes from the question where it says `output the sign` :)
### Explanation
Note: dividing the number by `pi` and multiplying it by `2` is the equivalent of dividing the entire number by `pi/2`
**Case `0`:**
`asin(0)` yields `0`. Taking the real part of it and dividing it by `pi/2` makes no difference to the output.
**Case `positive`:**
`asin(1)` yields `pi/2`. `asin` of any number bigger than `1` will give `pi/2` + complex number. Taking the real part of it gives `pi/2` and dividing it by `pi/2` gives `1`
**Case `negative`:**
`asin(-1)` yields `-pi/2`. `asin` of any number smaller than `-1` will give `-pi/2` + complex number. Taking the real part of it gives `-pi/2` and dividing it by `pi/2` gives `-1`
[Answer]
# V ~~14~~ 12 bytes
Thanks @DJMcMayhem for 2 bytes.
Uses a reg-ex to do the substitution. Kind of fun, because it's not a built-in. I have a more fun function, but it's not working the way I expected.
```
Í¨-©½0]/±1
```
[Verify Test Cases](https://tio.run/nexus/v#@3@499AK3UMrD@091GIQe6hR/9BGw///dc3MuEy5DLgMLQwMuHQtzQ0A)
This just translates to `:%s/\v(-)=[^0].*/\11` which matches one or more `-` followed by anything but 0, followed by anything any number of times. It's replaced with the first match (so either a `-` or nothing) and a `1`. The regex doesn't match 0, so that stays itself.
**The More Fun Way (21 bytes)**
```
é
Àé12|DkJòhé-òó^$/a
```
[TryItOnline](http://v.tryitonline.net/#code=w6kKw4DDqTEyfERrSsOyaMOpLcOyw7NeJC8SYQ&input=&args=LS0+LTY)
This accepts the input as an argument rather than in the buffer.
`é<CR>` Insert a new line.
`À` run the argument as V code. a `-` will move the cursor to the previous line, and any number will become the count for the next command
`é1` insert (count)`1`'s
`2|` move to the second column
`D` delete everything from the second column onwards (leaving only one character)
`kJ` Join the two lines together.
`òhé-ò` translates to: "run `hé-` until breaking". If the 1 was on the second line, this breaks immediately after the h. If it was on the first line, it will insert a `-` before breaking.
`ó^$/a` This fixes the fact that `-1`,`0`,`1` will leave a blank, and replaces a blank with the argument register.
[Answer]
# [Actually](https://github.com/Mego/Seriously), 1 byte
```
s
```
[Try it online!](https://tio.run/nexus/actually#@1/8/78pAA "Actually – TIO Nexus")
Another case of exactly what it says on the tin - `s` is the sign function.
Without the builtin (4 bytes):
```
;A\+
```
[Try it online!](https://tio.run/nexus/actually#@2/tGKP9/78BAA "Actually – TIO Nexus")
`;A\` divides the absolute value of the input by the input. This results `-1` for negative inputs and `1` for positive inputs. Unfortunately, due to Actually's error handling (if something goes wrong, the command is ignored), `0` as input leaves two `0`s on the stack. `+` rectifies this by adding them (which causes an error with anything else, so it's ignored).
[Answer]
# [Python 3](https://www.python.org/), 20 bytes
Since Python 3 doesn't have access to cmp like Python 2 does, it's a little longer
```
lambda n:(n>0)-(n<0)
```
]