-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathelementary.js
More file actions
56 lines (53 loc) · 887 Bytes
/
elementary.js
File metadata and controls
56 lines (53 loc) · 887 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
function multiply(a,b){
let sign=false
if ((a<0 && b>0) || (a>0 && b<0)){
sign=true
}
a=Math.abs(a)
b=Math.abs(b)
let n=0
for (let i=0;i<b;i++){
n=n+a
}
if (sign==true){
return Number("-"+n)
}
return n
}
function divide(a,b){
let sign=false
if ((a<0 && b>0) || (a>0 && b<0)){
sign=true
}
a=Math.abs(a)
b=Math.abs(b)
if (a<b){
return 0;
}
let n=0
while (a>0){
a-=b
n++
}
if (a<0){
n--
}
if (sign==true){
return Number("-"+n)
}
return n
}
function modulo(a,b){
let sign=false
if (a<0){
sign=true
}
a=Math.abs(a)
b=Math.abs(b)
a= a-multiply(divide(a,b),b)
if (sign==true){
return Number("-"+a)
}
return a
}
// console.log( modulo(123, -22))