Jim Brown Active Member Licensed User Longtime User Feb 20, 2011 #1 Can you implement the ATan2() function Erel? All parameters and return values as Double B4X: r=ATan2(y,x) - return value in radians d=ATan2D(y,x) - return value in degrees b4a has Floor() but no Ceil() Is Round() the exact equivalent to Ceil()?
Can you implement the ATan2() function Erel? All parameters and return values as Double B4X: r=ATan2(y,x) - return value in radians d=ATan2D(y,x) - return value in degrees b4a has Floor() but no Ceil() Is Round() the exact equivalent to Ceil()?
Erel B4X founder Staff member Licensed User Longtime User Feb 20, 2011 #2 Atan2 and Ceil will be added in the next update. Ceil is not equivalent to Round. Here is an implementation of Ceil: B4X: Sub ceil(Number As Double) As Double Dim f As Double f = Floor(Number) If f = Number Then Return Number Else Return f + 1 End Sub
Atan2 and Ceil will be added in the next update. Ceil is not equivalent to Round. Here is an implementation of Ceil: B4X: Sub ceil(Number As Double) As Double Dim f As Double f = Floor(Number) If f = Number Then Return Number Else Return f + 1 End Sub
klaus Expert Licensed User Longtime User Feb 20, 2011 #3 The Ceil code should be: B4X: Sub Ceil(Number As double) As double Dim f As Double f = Floor(Number) If f [COLOR=red]<[/COLOR] Number Then Return f Else Return f + 1 End Sub Best regards. EDIT: The code above is wrong Erel's code is right! Last edited: Feb 20, 2011
The Ceil code should be: B4X: Sub Ceil(Number As double) As double Dim f As Double f = Floor(Number) If f [COLOR=red]<[/COLOR] Number Then Return f Else Return f + 1 End Sub Best regards. EDIT: The code above is wrong Erel's code is right!
Erel B4X founder Staff member Licensed User Longtime User Feb 20, 2011 #4 Are you sure? Try: Ceil(5.1) Your code will return 5 instead of 6.
Jim Brown Active Member Licensed User Longtime User Feb 20, 2011 #6 Thanks Erel for ATan2D() I am using this at the moment (as used in my SnookerSim posted in user creations): B4X: Sub ATan2D(y As Float,x As Float) As Float If x<0 Then If y<0 Then Return ATanD(y/x)-180.0 Return ATanD(y/x)+180.0 End If Return ATanD(y/x) End Sub
Thanks Erel for ATan2D() I am using this at the moment (as used in my SnookerSim posted in user creations): B4X: Sub ATan2D(y As Float,x As Float) As Float If x<0 Then If y<0 Then Return ATanD(y/x)-180.0 Return ATanD(y/x)+180.0 End If Return ATanD(y/x) End Sub