Skip to content

Commit

Permalink
Corrigir arredondamento
Browse files Browse the repository at this point in the history
  • Loading branch information
dgadelha committed Aug 10, 2023
1 parent 2195086 commit 79cb381
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/runtime/src/libs/Matematica.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ export default /* javascript */ `{
arredondar(numero, casas) {
self.runtime.expectType("arredondar", "numero", numero, "inteiro", "real");
self.runtime.expectType("arredondar", "casas", casas, "inteiro", "real");
self.runtime.expectType("arredondar", "casas", casas, "inteiro");
return new PortugolVar(self.runtime.assumeMathType(numero, casas), Math.round(numero.value * Math.pow(10, casas.value)) / Math.pow(10, casas.value));
return new PortugolVar(self.runtime.assumeMathType(numero, casas), Number(numero.value.toFixed(casas.value)));
},
valor_absoluto(numero) {
Expand Down
4 changes: 2 additions & 2 deletions packages/runtime/src/runtime/PortugolRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,9 +379,9 @@ class PortugolRuntime {
}
expectType(fn, param, obj, ...types) {
if (!types.includes(obj.type) || obj.value === undefined) {
if (!obj || !types.includes(obj.type) || obj.value === undefined) {
let multipleTypesPlural = types.length > 1 ? "s" : "";
throw new Error("Tipos incompatíveis! O parâmetro '" + param + "' da função '" + fn + "' espera uma expressão do" + multipleTypesPlural + " tipo" + multipleTypesPlural + " " + types.map((c) => "'" + c + "'").join(" ou ") + (obj.value === undefined ? " com valor" : "") + ", mas foi passada uma expressão do tipo '" + obj.type + "'" + (obj.value === undefined ? " vazia" : ""));
throw new Error("Tipos incompatíveis! O parâmetro '" + param + "' da função '" + fn + "' espera uma expressão do" + multipleTypesPlural + " tipo" + multipleTypesPlural + " " + types.map((c) => "'" + c + "'").join(" ou ") + (obj?.value === undefined ? " com valor" : "") + ", mas foi passada uma expressão do tipo '" + (obj?.type ?? "vazio") + "'" + (obj?.value === undefined ? " vazia" : ""));
}
}
Expand Down

0 comments on commit 79cb381

Please sign in to comment.