[Question]
  [
[Ash](https://github.com/Radvylf/ash) has a bit of an interesting float division algorithm. It's designed to never return `NaN`, and things like signed zero and infinity need to be handled.
**How it works:**
Assume the inputs are positive for the rules below. One input being negative will always result in the output being negative, and both being negative will result in a positive output.
* Zero divided by anything is `0`
* Anything other than `0` divided by `0` is `Infinity`
* Anything other than `Infinity` divided by `Infinity` is `0`
* `Infinity` divided by anything other than `Infinity` is `Infinity`
* `Infinity` divided by `Infinity` is `1`
* All other division works as normal
**I/O:**
For languages with floats that support signed zero and positive/negative infinity, floats are an accepted I/O format. For others, using a string is allowed. You can use any reasonable format in this string, and you can represent the infinities with anything that can't be confused with another number (such as `I`, `∞`, `inf`, or `:(`).
Input will always be two floats in your chosen representation, and output will be a single one. Floating point errors and large numbers being represented as `Infinity` are allowed.
**Test cases:**
```
0 / 0                   0
0 / 1                   0
0 / 8                   0
0 / Infinity            0
0 / -0                 -0
0 / -1                 -0
0 / -8                 -0
0 / -Infinity          -0
-0 / 0                 -0
-0 / 1                 -0
-0 / 8                 -0
-0 / Infinity          -0
-0 / -0                 0
-0 / -1                 0
-0 / -8                 0
-0 / -Infinity          0
1 / 0                   Infinity
8 / 0                   Infinity
Infinity / 0            Infinity
1 / -0                 -Infinity
8 / -0                 -Infinity
Infinity / -8          -Infinity
-1 / 0                 -Infinity
-8 / 0                 -Infinity
-Infinity / 0          -Infinity
-1 / -0                 Infinity
-8 / -0                 Infinity
-Infinity / -0          Infinity
Infinity / 1            Infinity
Infinity / 8            Infinity
Infinity / -1          -Infinity
Infinity / -8          -Infinity
-Infinity / 1          -Infinity
-Infinity / 8          -Infinity
-Infinity / -1          Infinity
-Infinity / -8          Infinity
Infinity / Infinity     1
Infinity / -Infinity   -1
-Infinity / Infinity   -1
-Infinity / -Infinity   1
1 / 1                   1
1 / 8                   0.125
1 / Infinity            0
1 / -1                 -1
1 / -8                 -0.125
1 / -Infinity          -0
-1 / 1                 -1
-1 / 8                 -0.125
-1 / Infinity          -0
-1 / -1                 1
-1 / -8                 0.125
-1 / -Infinity          0
8 / 1                   8
8 / 8                   1
8 / Infinity            0
8 / -1                 -8
8 / -8                 -1
8 / -Infinity          -0
-8 / 1                 -8
-8 / 8                 -1
-8 / Infinity          -0
-8 / -1                 8
-8 / -8                 1
-8 / -Infinity          0
1 / 0.125               8
0.1 / 0.2               0.5
10 / -3                 -3.333333
1 / 0.0000000000000001  10000000000000000
```
**Other:**
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so shortest answer in bytes (per language) wins!
  
[Answer]
# [Haskell](https://www.haskell.org/), 35 bytes
```
x?y|isNaN$x/y=tanh x*tanh y|0<1=x/y
```
[Try it online!](https://tio.run/##lVRda8IwFH3vrwgifqxGG2UQxLqXMRiIL9vb2EOHUcNqKm1FK/53l6ZVW3uvZXkpzTk599ybcNZe9Ct8/3w@vCQnGc29efMwSNzYU2tyeDKf5ORMmKt3zxtPKncRWOTr0Et6x@8J3XjbTii8xXj8EYdSrej0Ndj9@KLb3wfhIuovpR@LsDNw24N2d9KcrkQ8k0pYRC6Jrui6x1Yrkiu123T0b9d1sx9yJPFaKLLVmjH5DHf6hPAjQba7WBeaqWbjzdP/Y9Kw7Wgd7M1p2270LhvkaJHU7tkhA@KQ6nKsFGEowlHkXS2lknFSRWi1EM0RhiIcRaqFNELhhi4IQxGOIngdoKELwlCEo0i1kGMx5H4uXIvXEa6qd7wrgSFXUyrxkFAoUWzvRqBwGwUCryPAbdyVAFyWSzwkFNtwHk@S1Y2a1xGKL@Q/k4RNwIRahaIJmMAfd1F6sqxkvwBRVhLFkeIhZh4mlEAZAiZQnw2fDQqnEEOyJlMEs@aqiOQNbDLtiyGpYhQpQ5MFMZkrQvlxUwQzhCNz5Abh4IQ5OkOOzDBTg2aYqSHzg81pNQqbSyfL0dkh5nI1wFyuhmdvOtuKmt412LByE/qtmCwfVY2P@iOzcl2nvLRpdrfl/AE "Haskell – Try It Online")
The relevant function is `(?)`, which takes two `Double`s as input and returns a `Double` as output.
## How?
The hyperbolic tangent is an amazing function (two bytes shorter than `signum`!).
| `x` | `tanh x` |
| --- | --- |
| `0.0` | `0.0` |
| `-0.0` | `-0.0` |
| `Infinity` | `1.0` |
| `-Infinity` | `-1.0` |
# [Haskell](https://www.haskell.org/), ~~30~~ 29 bytes
```
x?y|x/y<=1/0=x/y|0<1=tanh$x*y
```
[Try it online!](https://tio.run/##lVRda8IwFH3vrwgiU6exucogiNlexmCwt@1t7KHDqGU1SlvRyv67Sz/U1t5rWZ7anJNzzz0Jd@lFPzoIjsf9U/K7d5OpAlco@/ErpqBizyzb@/vkuPJ8o2Zrh33uB8ng8DXlK2/TDbU3m0ze49A3C/74vN5@B7o33K3DWTSc@0Gsw66rOm6nN20/LnT85hvtMH/ObC2lDnd3kb8w21XX/vaUyn/YgcVLbdjGasbsI9zaEzqINNtsY1vozbRbL579n7BWvx8t17vsdL/fGpw22MFhqd2jYC4TrL6EkyJAIpJEXs3cN36c1BFeL8QLBEhEkki9kEU43tAJARKRJELXQRo6IUAikkTqhYQDxP2cuI5sIpxVr3hnAhBXUylxk1AqUW7vQuB4GyWCbCLgbVyVQFxWS9wklNsQt5OEpqhlE6H8Qv6TJG4CJzQqlE3gBHm7i8qThYr9EsShIkoj5UOQPUxsAuUIOoGGMHrIUHwKATFrckV01pwViXmDm0z7AmKqZIocyMlCmCwUsflxUURniCRylBki0YQlmaEkMszVsAxzNSI/3JxV47i5NFlJZkeYK9QQc4UaPXvTbGtqdjfDRrWbsG8lm@XjuvHxcJytQldUlzUNV1viDw "Haskell – Try It Online")
Using [MarcMush](https://codegolf.stackexchange.com/a/223173/82619)'s amazing trick, which relies on the well-known formula1
$$
\tanh(x\cdot y)=\tanh(x)\cdot\tanh(y).
$$
---
1 I know, I know, maths.
[Answer]
# JavaScript (ES6), 45 bytes
Expects `(a)(b)`, as Numbers. Returns a Number.
```
a=>b=>a/b||+(b?1/a?a/b:a*b>0||-1:1/a/b<0&&-0)
```
[Try it online!](https://tio.run/##lVTNbtpAGLzzFKsc8G6C7d2gSCtaw6mVemgvHEsVrc2auCI2tZ2qUekbVOolx/Y9@jx5gT4CWf8ANv4@rPoAyc4w33zj1XxWX1UWpNEmt@NkqXeht1Pe1PemyvW32yvqz4SrZuafibr0p3y7tcXEnLj@az4c2pztUv3lIUo1tcLMYk6q1fJttNbzxzignDl5Ms/TKF5R5mSbdZTTi0V8wZwwSd@o4I5mxJuS7wNCPt6OiBoRf0T0t40Ocr0kn4hHMude5Ybn0sX8ipGFS6o/Lssvlxl4Qz883Ps6Za@MTKqNIgmpYtQvD4IkzpK1dtbJilb6hjKqeN5x1nBI3qv8zsmiVUwFcQsCKxjt0z2fkRmx/v399fz7yXxaZEKs5z8/LTPxB9txQ@Sk@/BBgQgUkSjyLg6jOMofu4jdHWTXiEARiSLdQQax4YX2iEARiSL4HGChPSJQRKJIdxAfCOT97LkD2Uc4qJ7wDgSBvJrWiLOExojmekeCDa/RIMg@ArzGyQjAZXvEWUJzDX4@SdEXtewjNG/I/yQJm4AJvQpNEzBBnt@idWVFy34DskVLFEeaPxLlxYQaqELABnLE9U2Jwi0kkK6pFMGuOSgifQObLPYSSKuUirZAmwUxWStC/XFUBDtEIjnKEpFgwhLNUCIZVmpQhpUakh9szqjZsLkiWYlmh5ir1QBztRrevUW2HTVzWmLXnTdh7krZ5eOu8bEzbj839QTefox9cXLEXwA "JavaScript (Node.js) – Try It Online")
## How?
Let \$\mathbb{R}^\*\$ be \$\{x\in\mathbb{R}\mid x\neq0\}\$.
### Direct answers when `a/b` is truthy
Whenever \$a/b\$ is neither `NaN` nor \$0\$, we know for sure that it is the expected answer. The cases that are covered that way are:
* \$a\in\mathbb{R}^\*\$, \$b\in\mathbb{R}^\*\$ : standard division of non-zero, non-infinite floats
* \$a\in\mathbb{R}^\*\$, \$b=\pm0\$ : resulting in either \$+\infty\$ or \$-\infty\$
* \$a=\pm\infty\$, \$b\in\mathbb{R}^\*\$ : resulting in either \$+\infty\$ or \$-\infty\$
* \$a=\pm\infty\$, \$b=\pm0\$ : resulting in either \$+\infty\$ or \$-\infty\$
### Other cases
If \$a/b\$ is zero'ish, we test \$b\$:
* If \$b\neq\pm0\$:
	+ If \$1/a\neq\pm0\$, \$a/b\$ is also the correct answer, which is either \$0\$ or \$-0\$
	+ If \$1/a=\pm0\$ (i.e. \$a=\pm\infty\$), we also have \$b=\pm\infty\$ and the answer is either \$1\$ or \$-1\$ depending on the sign of \$a\times b\$ (we do `a*b>0||-1`)
* If \$b=\pm0\$, we also have \$a=\pm0\$ and the answer is either \$0\$ or \$-0\$ depending on the signs of \$a\$ and \$b\$ (we do `1/a/b<0&&-0`)
---
# JavaScript (ES6), ~~42~~ 33 bytes
Using [MarcMush's improvement](https://codegolf.stackexchange.com/a/223173/58563) of [Delfad0r's excellent trick with **tanh**](https://codegolf.stackexchange.com/a/223169/58563) saves ~~3~~ 12 bytes.
```
a=>b=>a/b<=1/0?a/b:Math.tanh(a*b)
```
[Try it online!](https://tio.run/##lVTLbtNAFN3nK666qGdK/JhGlUalTlcgsYBNlg1CY2ecGKV2aruICvEHSGxYwn/0e/oDfEIYP5LY8b2x8CKJ5pyce@7x6HxWX1QeZvGmsJN0obeRv1X@NPCnyg1ufOF6t@bH9XtVrJxCJSumLgK@zfTDY5xpZkW5xZ1Mq8XbeK1nT0nIPO4U6azI4mTJuJNv1nHBzubJGXeiNHujwhXLwZ/CtxHA3acxqDEEY9BfNzos9AI@gg@5c68Kw3PZfPaKw9yF@sdF9eVyA2/Yh8f7QGf8tZHJtFGEiCnOguogTJM8XWtnnS5ZrW8o45rnH2adn0O1Vh4vEybALQm8ZHRPd3wOt2D9ff758vuX@bTgGqyXPz8sM/E733qG6EH/8UYlIkhEksi7JIqTuHjqI3Z/kN0ggkQkifQHGcTGF9ohgkQkidBzkIV2iCARSSL9Qd5IEO9nxx3JIcJe9Yi3Jwji1XRGnCS0RrTXOxBsfI0WQQ4R8DWORiAuuyNOEtpreKeTFENRyyFC@4b8T5K4CZwwqNA2gRPk6S06V1Z07LcgW3REaaT9J1FdTKyBagRtIEdcXlUo3kKC6JpaEe2avSLRN7jJci9BtEqlaAuyWQiTjSLWHwdFtEMkkaOsEIkmLMkMJZFhrYZlWKsR@eHmjJqNmyuTlWR2hLlGDTHXqNHdW2bbUzOnFXbZexPmrlRdPukbnziT7nPVTPC6j7Evjo68fw "JavaScript (Node.js) – Try It Online")
[Answer]
# [Julia 0.7](http://julialang.org/), 26 bytes
imaginary brownie points for using `tanh` instead of `sign` (thanks [Delfad0r](https://codegolf.stackexchange.com/a/223169/98541))
```
a$b=a/b<=Inf?a/b:tanh(a*b)
```
[Try it online!](https://tio.run/##lVbLTsMwELznK6yIg4OS1NvysBAVNyS@ARByRCqCIrdqzIE/gN/kR4LjpMWpdxORSyPPdHZ2bY3z/lFX6rpt1VmxVovidv2gN3f25cYo/cbVeZG0pmxMw9YsjuNIsAUTLHyEQ4BEJInYepWuzGeIZGGhbECARCSJhIUskuENHRAgEUkidB2koQMCJCJJJCwkIiD258CN5BzhqHrCOxKA2JpRiUmCV8Jv74@Q4W14BDlHwNs4KYG4HJeYJPhtiOlJwtyo5RzBPyH/mSRuAifMKvgmcIKc7mJ0ZGFk34MyGInSiP8ncAcTS6AeQRMoh@WlQ/EUAiJrekU0a46KRN7gJru@gEgVp5gBmSyEyUERy48/RTRDJDFH6RCJTliSM5TEDHs1bIa9GjE/3JxVy3Bz3WQlOTvC3KCGmBvU6OztZhuo2VWHLYOdsGfFZfkqNL7KV/4zyIvxY73DyZLo7ulos90zrtKXtEjLhFWaNbu6Mjl3P9xd6SmLn3ScJJGrpzqmveV3at@UOb@vt8pcXaTs0QHPA2u3r7SpNeduNWX2syFl5c/3l32xSqV@bX8B "Julia 0.7 – Try It Online")
[Answer]
# [R](https://www.r-project.org/), ~~98~~ ~~95~~ ~~89~~ 88 bytes
-6 bytes thanks to Giuseppe
```
function(x,y=abs(scan(t=x)))cat("-"[!!sd(grepl("-",x))],c(z<-y[1]/y[2],!!y)[1+is.na(z)])
```
[Try it online!](https://tio.run/##bcxBDsIgEAXQvacos5qJoNaViXKAngFZIIppYkZTaFJ6eSxdGjfz8/PyZyhBlzCyT/2bcZJZu1vE6B1j0hMReZcQFBgh4h2fw@PzqlUuZKXH@aKyae0@m6OVQmQy7baPO3Y4k6US0CMcQDbLITo367MrA21WUR2HijX@8Kma@l2WLw "R – Try It Online")
Expects a vector of strings, as R cannot handle signed 0. Infinity will be input and output as `Inf`.
* `x` contains the input as 2 strings, and `y` is the conversion to numeric in absolute value.
* First, call `grepl("-",x)`, giving a vector of two booleans. We need to output a `-` sign iff the two booleans are different, ie if the standard deviation is non-0.
* Second, compute the division of the two values. R's division agrees with Ash's in most cases, but will give `NaN` for the two cases which are ambiguous: `0/0` and `Inf/Inf`. If the quotient is not NaN, we output it; otherwise, we compute the boolean `!!y[1]`, convert to integer, and output that.
Note that we can use `is.na` instead of `is.nan`, as `is.na(NaN)` returns `TRUE`. (The two functions are nonetheless not equivalent; `is.nan(NA)` returns `FALSE`.)
[Answer]
# [Scratch](https://scratch.mit.edu/), 310 bytes
[Try it online!](https://scratch.mit.edu/projects/513598083/)
In scratchblocks4:
```
when gf clicked
ask()and wait
set[N v]to(answer
ask()and wait
set[D v]to(answer
set[Q v]to((N)/(D
if<(Q)=[NaN]>then
if<(A)contains(0)?>then
set[Q v]to(0
else
set[Q v]to(1
end
end
if<<(join(N)(D))contains(-)?>and<not<<(N)contains(-)?>and<(D)contains(-)?>>>>then
if<(Q)contains(-)?>then
else
set[Q v]to(join(-)(Q
```
Alternatively, 37 blocks. No picture this time!
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 32 bytes
```
a=>b=>a/b+b/a?a/b:Math.sign(a*b)
```
[Try it online!](https://tio.run/##lVVdb4IwFH3nV/TNdkChmiXNDO5pD3tY9gPmMgtDxSAYIUuWZb@dlQ8V7L2SNTGYnsO59542h536UkV0TA6lm@WfcbUOKhUswmChvNAOPfWonw8vqtzyItlkVN2FrCrjoiQBWVk@8YhPzOU3iEARiSLP2TrJkvLbRFyzkNshAkUkipiFNOLCA50QgSISRfA6wEAnRKCIRBGzkG8J5HxOXEuOEc6qV7wzQSBHMyhxk9Ar0R/vQnDhMXoEOUaAx7gqAXQ5LHGT0B/Dv@2kGLNajhH6N@Q/TsJNwIRRhX4TMEHenmJwZcWg/R7kioEojvRfEs3FhBKoRcAE4mJ636BwCgkka1pFMGvOikjewE3WcwkkVRpFV6DJgjTZKUL5cVEEM0QiPsoGkaDDEvVQIh62apCHrRriH9ycVnPh5mpnJeod0lynBjTXqeHZW3trqOndBpsaJ6HvSpPlM7PxGZ8Zq6vhD5ceQFxt@daKl8dkTxkvDmlS0skymzC@VweakmBB0m7bWxa2x9jcqr/wfJ0fn1S0pfRNOR9O6MTvrCb/WITk@vO/prZi1A41nZAoz4o8jXmab@hruIujkicFtWOH5MwhttK/UP/Xj1jzf9m8@gM "JavaScript (Node.js) – Try It Online")
| Rule | JavaScript (IEEE 754) |
| --- | --- |
| Zero divided by anything is `0` | 0/0 is NaN;Same results for other values |
| Anything other than `0` divided by `0` is `Infinity` | Same Results |
| Anything other than `Infinity` divided by `Infinity` is `0` | Same Results |
| `Infinity` divided by anything other than `Infinity` is `Infinity` | Same Results |
| `Infinity` divided by `Infinity` is `1` | Infinity/Infinity=NaN |
| All other division works as normal | Same Results |
From above comparsion, we can see that, we only need to handle values when `a/b` is NaN. And whenever `a/b` is NaN, `Math.sign(a*b)` is what we want here.
So we use `a/b+b/a` to test `NaN` here. As long as `a/b` is not `NaN`, `a/b`, `b/a` have same signs. And adding them would always yield non-zero value. We know only `0`, `-0`, `NaN` is falsy. And the value here is non-zero. So we can ensure the result is `NaN` if `a/b+b/a` is falsy.
[Answer]
# [C (gcc)](https://gcc.gnu.org/), ~~169~~ 157 bytes
Thanks to @ceilingcat for the -12.
`tanh` seems like the way to go if you want to win this one, so I decided to try this without using any intrinsics, looking at the sign and exponents instead. `NaN` and denormals are not handled.
Annotated version:
```
*i,*j,w,x,t,u,v; char*z;
float f(a,b) float a,b; {
  i=&a; j=&b; // Get the integer representations of the floats
  w=*i*2; x=*j*2; // Move the exponents into the MSB of a copy
  t=*j; // Save the original value that will be clobbered
  u=3[z=&w]; v=3[z=&x]; // Get the exponents
  b=v?
      ~v? // x/!0
        ~u?
          j=0,a/b: // !INF/!(0,INF)=a/b (indicate normal division)
          1/0.: // INF/!(0,INF)=INF
        !~u: // INF/INF=1 or !INF/INF=0
      u? // x/0
        1/0.: // !0/0=INF
        0; // 0/0=0
  // Adjust the sign if normal division not used
  // (if one value is negative, it will flip the sign)
  j?*j^=(*i^t)&1<<31:0;
  a=b; // Store the result in the return
}
```
```
*i,*j,w,x,t,u,v;char*z;float f(a,b)float a,b;{i=&a;j=&b;w=*i*2;x=*j*2;t=*j;u=3[z=&w];v=3[z=&x];b=v?~v?~u?j=0,a/b:1/0.:!~u:u?1/0.:0;j?*j^=(*i^t)&1<<31:0;a=b;}
```
[Try it online!](https://tio.run/##bVDRboIwFH3nKzqXEahVC2aJsXS8LfHFp70sDpOCMtsoLAzQaNyvs9uqQ80IOff0nHMvlya9zyRpGiwJVmRLdqQkFalZshIF3rN0nYsSpY4gsXviwNhBclswxe2YbTmW2Gc7jhWUEgqr@HC25/Y2YvWJ7SIW8zr8gbcKFadEDOKxN6D98cNPNa5CQylTIVZz7mA5L13bC4KhB6LgMTs2jzJL1tViiYLvciHz/urFaqWNKFdasWRWoo2QmVPncuGig4XQeedZxA@0TwnqGfQMNTgy1OBk@jqZTt7e4XyhR2bpIXnh6NmSU4ZkMALodl0wWktpS2lLXSyEvgqwUqfzlKIBAuAAH1mHwD4y0qgA4W7/Tq5rvnfpgwWhkfY9/7ntTR2zt1F1vo2DZOL@dRhEHfZvox41o3tDKNeTT3cE6l38vAi9fbx/trqPnH@pWJZVkSHKrGPzCw "C (gcc) – Try It Online")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 48 bytes
```
ẸṂ=?
ñç÷?
÷×¹?
®+©ṛ
”-eÇ
Ḋ⁸Ç?
ɠÇŒV
-1*®
7£2ŀ7£×¢
```
Takes input as newline-separated strings in STDIN, zero is `0.0`, and infinity is `inf`.
[Try it online!](https://tio.run/##AVwAo/9qZWxsef//4bq4MD0/CsOxw6fDtz8Kw7cwwrk/CsKuK8Kp4bmbCuKAnS1lw4cK4biK4oG4w4c/Csmgw4fFklYKLTEqwq4KN8KjMsWAN8Kjw5fCov//LWluZgotMw "Jelly – Try It Online")
### How?
```
ẸṂ=?           - 1: λxλy: any(x, y) if x == y else min(x, y)
ñç÷?           - 2: λxλy: line3(x, y) if x÷y else line1(x, y)
÷×¹?           - 3: λxλy: x÷y if x else x×y
®+©ṛ           - 4: λx: add x to register; return x
”-eÇ           - 5: λx: link4("-" in x)
Ḋ⁸Ç?           - 6: λx: x[1:] if link5(x) else x
ɠÇŒV           - 7: eval(link6(read from stdin))
-1*®           - 8: (-1)^register
7£2ŀ7£×¢       - main: link2(link7, link7) * link8
```
]