Page 1 of 2
More simple math functions...
Posted: Mon Feb 21, 2005 1:59 pm
by Lebostein
In every basic language in this world (apart form PB) i found follow simple functions:
Abs(x) - returns the absolute value of a number (for integers)
Swap(x,y) - exchanges the values of the variables
Sign(x) - returns a positive, zero, or negative integer based on the sign of argument
please implement this simple functions. Thanks!
PS: Why not exists a konstant of "PI", like #PI = 3.14159265359?
Posted: Tue Feb 22, 2005 10:37 am
by FloHimself
#PI = 3.14159265359
Numeric overflow: too big number

Posted: Tue Feb 22, 2005 10:40 am
by Inner
Abs() exists.
Posted: Tue Feb 22, 2005 10:40 am
by IceSoft
FloHimself wrote:#PI = 3.14159265359
Numeric overflow: too big number

Not with PB 4.0

Posted: Tue Feb 22, 2005 12:27 pm
by FloHimself
see your signature!

Posted: Tue Feb 22, 2005 2:24 pm
by Lebostein
Inner wrote:Abs() exists.
..only for float numbers!!! Read the manual accurately and you see: "This function works correctly only with float numbers. With integer it will fail if the integer is too big (loss of precision). Another function will be added to do that." (
http://www.purebasic.com/documentation/index.html)
The label "Abs()" for this function is actual confusing, "AbsF()" is better - like Str() and StrF().
Hehe, sorry for my PI:
Posted: Tue Feb 22, 2005 5:48 pm
by Andras
Pi=ATan(1)*4
Posted: Tue Feb 22, 2005 6:10 pm
by NoahPhense
Andras wrote:Pi=ATan(1)*4
- np
Posted: Tue Feb 22, 2005 6:33 pm
by Psychophanta
Lebostein wrote:The label "Abs()" for this function is actual confusing, "AbsF()" is better - like Str() and StrF().
Hehe, sorry for my PI:
You are right about the syntax incoherence. I second that.
As you can see #PI constant sould be better to be stablished when 64, 80, (and 128) bit floats are available.
Inner wrote:Abs() exists.
Yeah. Just like God. But not for integers, but for fractionated ones.
BTW, shorter:

Posted: Tue Feb 22, 2005 7:04 pm
by NoahPhense
LOL
Code: Select all
; The result will be output to approximately the number of decimal places requested
; Initially try 770 decimal places. The last 8 digits should be 9999 9983
Declare addbtoa()
Declare subbfroma()
Declare divcby25()
Declare divdby57121()
Declare divcbyn()
Declare divdbyn()
Global d, x, n
OpenConsole()
Print("Number of decimal places? ")
np=Val(Input())
If np<4: np=4: EndIf
PrintN("")
x=10000 : xw=4
d=np/xw+2
; Working registers, each element holding an integer 0..9999
Dim a(d)
Dim b(d)
Dim c(d)
Dim d(d)
it=(np/Log10(25)+5)/2 ; Number of iterations
c(1) = 800 : d(1) = 9560 : n=-1
For j=1 To it
n + 2
divcby25()
divcbyn()
addbtoa()
divdby57121()
divdbyn()
subbfroma()
n + 2
divcby25()
divcbyn()
subbfroma()
divdby57121()
divdbyn()
addbtoa()
Next j
; Print result
Print(" 3.1")
For i=2 To d-1
Print(RSet(Str(a(i)),xw,"0")+" ")
If (i%15)=0
PrintN("")
EndIf
Next i
PrintN("")
PrintN("Press ENTER")
Input()
CloseConsole()
End
Procedure addbtoa() ; Multi-precision addition
c=0 ; Carry
For i=d To 1 Step -1
s = a(i)+b(i)+c
c = s/x
a(i) = s%x
Next i
EndProcedure
Procedure subbfroma()
c = 0
For i=d To 1 Step -1
s = a(i)-b(i)-c
If s<0
s + x: c = 1
Else
c=0
EndIf
a(i) = s%x
Next i
EndProcedure
Procedure divcby25()
r = 0 ; Remainder
For i=1 To d
c = c(i)+x*r
c(i) = c/25
r=c%25
Next i
EndProcedure
Procedure divdby57121()
r = 0
For i=1 To d
c = d(i)+x*r
d(i) = c/57121
r=c%57121
Next i
EndProcedure
Procedure divcbyn()
; b()=c()/n
r = 0
For i=1 To d
c = c(i)+x*r
b(i) = c/n
r=c%n
Next i
EndProcedure
Procedure divdbyn()
; b()=d()/n
r = 0
For i=1 To d
c = d(i)+x*r
b(i) = c/n
r=c%n
Next i
EndProcedure
- np
Posted: Tue Feb 22, 2005 8:32 pm
by ts-soft
Code: Select all
Procedure AbsL(Value.l)
If Value < 0 : Value = - Value : EndIf
ProcedureReturn Value
EndProcedure
Posted: Wed Feb 23, 2005 8:09 am
by Lebostein
ts-soft wrote:Code: Select all
Procedure AbsL(Value.l)
If Value < 0 : Value = - Value : EndIf
ProcedureReturn Value
EndProcedure
This is a wishlist forum and not a "how i can do...?". My ambition (vision) is a better Basic with all standard functions from the older/other Basics. I don't need this functions this time, I will reduce the work to convert code from other Basics to PB, for example.
These functions are very simple to implement.... I hope against hope

Posted: Wed Feb 23, 2005 9:21 am
by Psychophanta
Lebostein wrote:This is a wishlist forum and not a "how i can do...?". My ambition (vision) is a better Basic with all standard functions from the older/other Basics. I don't need this functions this time, I will reduce the work to convert code from other Basics to PB, for example.
These functions are very simple to implement.... I hope against hope

Well said Lebostein. Great. And I second your ambition for PB too

I think just that, and some other things, is what all the PB comunity member must want and try in order to get a better and better PB.

Posted: Tue May 13, 2008 9:53 pm
by Lebostein
Now, after 3 years since the last request, I see no change. I am very unhappy and discontented about the situation of the math library in PB! What is the problem to add this simple functions?

:roll:
Posted: Tue May 13, 2008 10:28 pm
by Fred
No need to dig up old posts and tell "man what are you doing here, it's alreay XX years and nothing comes" - it's annoying. This forum is for features request, not things to implement. If you are not happy with our decisions, write your own functions. BTW, 'swap' is here or i miss something ?