[Erlang] lists:seq for floats
%% This lets you do stuff like | |
1> my_lib:seq_float(10.01,10.13,0.02). | |
[10.01,10.03,10.05,10.07,10.09,10.11,10.13] |
-module (my_lib). | |
-export ([seq_float/3]). | |
seq_float(Min, Max, Inc, Counter, Acc) when (Counter*Inc + Min) >= Max -> | |
lists:reverse([Max|Acc]); | |
seq_float(Min, Max, Inc, Counter, Acc) -> | |
seq_float(Min, Max, Inc, Counter+1, [Inc * Counter + Min|Acc]). | |
seq_float(Min, Max, Inc) -> | |
seq_float(Min, Max, Inc, 0, []). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment