1. help?
- Posted by kobi May 06, 2012
- 1224 views
I'm sorry, I'm probably so dense today.
I can't see what's wrong in this little piece of code:
include std/math.e function minmax(atom min, atom max, atom val) atom temp = max ({min, val}) atom res = min({max, temp}) return res end function ? minmax(7.2,99,6)
thanks in advance, kobi
2. Re: help?
- Posted by DerekParnell (admin) May 06, 2012
- 1203 views
I'm sorry, I'm probably so dense today.
I can't see what's wrong in this little piece of code:
I don't know what you are trying to achieve so I can't tell what the correct result should be.
3. Re: help?
- Posted by ArthurCrump May 06, 2012
- 1198 views
Are you trying to achieve the same effect as ensure_in_range?
4. Re: help?
- Posted by ne1uno May 06, 2012
- 1202 views
I'm sorry, I'm probably so dense today.
I can't see what's wrong in this little piece of code:
include std/math.e function minmax(atom min, atom max, atom val) atom temp = max ({min, val}) atom res = min({max, temp}) return res end function ? minmax(7.2,99,6)
thanks in advance, kobi
besides reusing the max name? surprisingly legal in euphoria more often than not, but always confusing. another reason is to avoid catching euphoria on a bad day with an edge case. try something else more direct if it looks like a bug.
5. Re: help?
- Posted by ne1uno May 06, 2012
- 1207 views
I'm sorry, I'm probably so dense today.
I can't see what's wrong in this little piece of code:
function minmax(atom min, atom max, atom val) atom temp = math:max ({min, val}) atom res = math:min({max, temp}) return res end function
qualifying w/math: gets rid of the syntax error and produces 7.2 wrong again?
seems it should test min first otherwise should be called maxmin
probably a bug.
6. Re: help?
- Posted by kobi May 07, 2012
- 1163 views
Thanks for all the replies!
I got a syntax error and
didn't see that the variable name is the same as the function's name.
7. Re: help?
- Posted by DerekParnell (admin) May 07, 2012
- 1171 views
I can't see what's wrong in this little piece of code:
include std/math.e function minmax(atom min, atom max, atom val) atom temp = max ({min, val}) atom res = min({max, temp}) return res end function ? minmax(7.2,99,6)
Although your original problem has been resolved, you might like to consider a more straight forward version ...
function minmax(atom pMin, atom pMax, atom pVal) if pVal > pMax then return pMax end if if pVal < pMin then return pMin end if return pVal end function for i = 5 to 120 by 20 do ? {i, minmax(7.2,99,i) } end for
Also note that I've used my personal naming convention, that helps avoid name clashes.
- Parameters are prefixed with 'p'
- Variables local to a routine are prefixed with 'l'
- Variables local to a module (file) are prefixed with 'm'
- Variables that are exposed to other files are prefixed with 'g'
- Constants local to a file are prefixed with 'k'
- Constants that are exposed to other files are (usually) in all uppercase.
8. Re: help?
- Posted by kobi May 07, 2012
- 1153 views
function minmax(atom pMin, atom pMax, atom pVal) if pVal > pMax then return pMax end if if pVal < pMin then return pMin end if return pVal end function for i = 5 to 120 by 20 do ? {i, minmax(7.2,99,i) } end for
ah, yes, much easier to understand.