How do you multiply two float numbers without using multipliers?
-
How do you multiply two float numbers without using multipliers?
The chips can be any.
let a = 0.1; let b = 0.2;
-
Modalities
use of separation
const res = a / (1 / b);
Method universal in comparison with method (2), NEDROSTAT - if
b = 0
That way doesn't work.using logarithms and exhibitors
const res = Math.exp(Math.log(a) + Math.log(b))
2.1. Same as 2, but the degree and logarithm on the basis of 10 may be used:
const res = Math.pow(10, Math.log10(a) + Math.log10(b))
2.2. Same as 2, but the degree and logarithm on the basis of 2:
const res = Math.pow(2, Math.log2(a) + Math.log2(b))
There's a lot of options for logarithms, because you can use logarithms with arbitrary grounds.
But there's a NEDROSTAT - it's impossible to work with negative numbers and zero.
- Use tangenes:
any number can be imagined as a thangens angle
a = tan(x)
so we can use the trigonometric tone:tan(x + y) = (tan(x) + tan(y)) / (1 - tan(x)*tan(y))
in this way
1 - (a + b) / (tan(atan(a) + atan(b)) = a * b
I mean.
res = 1 - (a + b) / (Math.tan(Math.atan(a) + Math.atan(b))
NEXT: An option where
tan(atan(a) + atan(b) = 0
Again, because the functions are counted through the rows, the accuracy (almost)