Skip to content

Instantly share code, notes, and snippets.

@andruby

andruby/my_lib.erl

Created Nov 23, 2009
Embed
What would you like to do?
[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