Browse Source

Refactor max/min function to accept a vector as parameter

Lucas de Souza 5 years ago
parent
commit
40b979244a
1 changed files with 7 additions and 11 deletions
  1. 7 11
      js/processor/lib/math.js

+ 7 - 11
js/processor/lib/math.js

@@ -158,18 +158,16 @@ export function createInvertFun () {
 }
 
 export function createMaxFun () {
-  const minFun = (sto, _) => {
+  const maxFun = (sto, _) => {
     const x = sto.applyStore('x');
-    const y = sto.applyStore('y');
-    const result = BigNumber.max(x.value, y.value);
-    const temp = new StoreObject(Types.REAL, result);
+    const result = BigNumber.max(x.value);
+    const temp = new StoreObject(x.subtype, result);
     return Promise.resolve(sto.updateStore('$', temp));
   };
 
  const block = new Commands.CommandBlock([],  [new Commands.SysCall(maxFun)]);
  const func = new Commands.Function('$max', Types.ALL,
-   [new Commands.FormalParameter(Types.ALL, 'x', 0, false),
-   new Commands.FormalParameter(Types.ALL, 'y', 0, false)],
+   [new Commands.FormalParameter(Types.ALL, 'x', 1, false)],
    block);
  return func;
 }
@@ -177,16 +175,14 @@ export function createMaxFun () {
 export function createMinFun () {
   const minFun = (sto, _) => {
     const x = sto.applyStore('x');
-    const y = sto.applyStore('y');
-    const result = BigNumber.max(x.value, y.value);
-    const temp = new StoreObject(Types.REAL, result);
+    const result = BigNumber.max(x.value);
+    const temp = new StoreObject(x.subtype, result);
     return Promise.resolve(sto.updateStore('$', temp));
   };
 
  const block = new Commands.CommandBlock([],  [new Commands.SysCall(minFun)]);
  const func = new Commands.Function('$min', Types.ALL,
-   [new Commands.FormalParameter(Types.ALL, 'x', 0, false),
-   new Commands.FormalParameter(Types.ALL, 'y', 0, false)],
+   [new Commands.FormalParameter(Types.ALL, 'x', 1, false)],
    block);
  return func;
 }