Math: Add floor() and ceiling() functions
-
- Always Here
- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Math: Add floor() and ceiling() functions
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
Re: Math: Add floor() and ceiling() functions
Isn't this already implemented?
or if you prefer:
Code: Select all
Debug Round(f.f, #PB_Round_Up)
Debug Round(f.f, #PB_Round_Down)
Code: Select all
Macro floor(x)
Round(x, #PB_Round_Down)
EndMacro
Macro ceiling(x)
Round(x, #PB_Round_Up)
EndMacro
For i = 1 To 40
f.f = (i - 20) / 4
Debug "i: " + StrF(f) + ", up:" + Str(ceiling(f)) + ", down:" + Str(floor(f))
Next
-
- Always Here
- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: Math: Add floor() and ceiling() functions
It does not seem to have the precision required when using doubles. I have a work-around using strings and often the value is going to end-up being a string anyway.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
-
- Addict
- Posts: 4779
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: Math: Add floor() and ceiling() functions
Can you please post some code that demonstrates the problem?IdeasVacuum wrote:It does not seem to have the precision required when using doubles.
I'm using macros like the ones Demivec posted, and never encountered any problems.
Re: Math: Add floor() and ceiling() functions
Do you mean that the value of the number hovers around the integer value, sometimes higher and sometimes lower, so that when you round it up or down it goes the wrong way?IdeasVacuum wrote:It does not seem to have the precision required when using doubles. I have a work-around using strings and often the value is going to end-up being a string anyway.
If this is the case then perhaps using some form of fixed-decimal may be what you need.
-
- Always Here
- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: Math: Add floor() and ceiling() functions
Yes, I lost patience with it - I was at that time converting a simple, short piece of C++ code. However, the strings method is an altogether better solution for output.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.