copysign: Wasm numeric instruction
The copysign numeric instruction is used to copy just the sign bit from one number to another.
The **`copysign`** [numeric instruction](/docs/WebAssembly/Reference/Numeric) is used to copy just the sign bit from one number to another.
tabbed-taller
```wat interactive-example
(module
(import "console" "log" (func $log (param f32)))
(func $main
;; load `10` and a negative number onto the stack
f32.const 10
f32.const -2
f32.copysign ;; copy just the sign bit from second to the first number
call $log ;; log the result
)
(start $main)
)
```
```js interactive-example
const url = "{%wasm-url%}";
await WebAssembly.instantiateStreaming(fetch(url), { console });
```
## Syntax
```wat
;; load two numbers onto the stack
f32.const 10
f32.const -1
;; copy just the sign bit from the second number (-1) to the first (10)
f32.copysign
;; the top item on the stack will now be -10
```
| Instruction | Binary opcode |
| -------------- | ------------- |
| `f32.copysign` | `0x98` |
| `f64.copysign` | `0xa6` |
## Specifications
## Browser compatibility
Cite this
"copysign: Wasm numeric instruction". MDN Web Docs. CC BY-SA 2.5 (MDN). https://developer.mozilla.org/en-US/docs/WebAssembly/Reference/Numeric/copysign JSON record · API collection · BibTeX · RIS · CSL-JSON · citation policy