Math.max and Math.min only accept two parameters
- Lingua principale
- JavaScript
- Stelle
- 15.5k
- Fork
- 663
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione

## *What* is wrong?
Using `Math.max` with more than two parameters causes the GPU kernel build to fail.
## *How* do we replicate the issue?
```
const gpu = new GPU({ mode: 'gpu' });
const kernel = gpu.createKernel(function() {
return Math.max(0, 1, 2);
}).setOutput([1]);
kernel();
```
And observe the output error
`gpu-browser.js:14913 Uncaught Error: Error compiling fragment shader: ERROR: 0:457: 'max' : no matching overloaded function found`. Replacing `0, 1, 2` with `0, 1` (or any other two numbers) leads to the function behaving as expected. The same is true of `Math.min`.
JS Fiddle: [https://jsfiddle.net/TomWyllie/opdg95kb/](https://jsfiddle.net/TomWyllie/opdg95kb/)
GPU.js 2.9.4
GPU: NVIDIA GeForce GTX 1060 3GB
Nvidia Driver 446.14
Google Chrome Version 83.0.4103.97 (Official Build) (64-bit)
Windows 10
## *How* important is this (1-5)?
2, it's very easy (but pretty messy) to workaround by using `Math.max(x, Math.max(y, Math.max(z, t)));` or similar, but that is pretty ugly. My understanding is that the [spec](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/max) allows arbitrarily many parameters.
## Other Comments
I'm beginning to think there might be something deeper wrong with GPU.js on my machine given this issue and the other I filed several days ago (#617) must be very common use cases and surely lots of other people would be having these same problems... any thoughts appreciated.
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
Inizia riproducendo l’esempio di kernel GPU.js fornito con Math.max e Math.min usando tre o più argomenti, quindi esamina come queste chiamate vengono tradotte nello shader GPU. Il lavoro è completato quando le chiamate con più argomenti vengono compilate e restituiscono il risultato previsto senza richiedere workaround annidati; verifica l’esempio originale e il caso con due argomenti.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- javascript
- Ambito
- computer-graphics
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100