Adriandmen / 05AB1E

A concise stack-based golfing language
MIT License
760 stars 48 forks source link

Fix the pow function when using floating point numbers #169

Closed Adriandmen closed 4 years ago

Adriandmen commented 4 years ago

Description

Since Elixir and Erlang do not supply their own implementation to support arbitrary precision with the :math.pow/2 function, we implemented our own pow method that handles arbitrary precision. However, when using floating point numbers, this may result in an infinite loop – most likely caused by the following line of code:

https://github.com/Adriandmen/05AB1E/blob/5ae97149e3e4758e39d351728ce013fd53f2f3c1/lib/commands/int_commands.ex#L81

This has now been fixed by including 0 as well to the range:

https://github.com/Adriandmen/05AB1E/blob/bb62507722e68af12123cf09d9a3ad7dda4721bd/lib/commands/int_commands.ex#L83

A failsafe check has been added as well before entering the recursive pow computation:

https://github.com/Adriandmen/05AB1E/blob/bb62507722e68af12123cf09d9a3ad7dda4721bd/lib/commands/int_commands.ex#L84

codecov[bot] commented 4 years ago

Codecov Report

Merging #169 into master will decrease coverage by 0.16%. The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #169      +/-   ##
==========================================
- Coverage   95.93%   95.76%   -0.17%     
==========================================
  Files          23       23              
  Lines        1794     1795       +1     
==========================================
- Hits         1721     1719       -2     
- Misses         73       76       +3     
Impacted Files Coverage Δ
lib/commands/int_commands.ex 98.95% <100.00%> (+<0.01%) :arrow_up:
lib/interp/functions.ex 93.25% <100.00%> (ø)
lib/commands/gen_commands.ex 94.23% <0.00%> (-1.93%) :arrow_down:
lib/interp/commands/unary_interp.ex 98.87% <0.00%> (-0.57%) :arrow_down:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 5ae9714...bb62507. Read the comment docs.