Hi,
I'm just trying to write my first library widget using LCB and need to calculate the square root of several numbers. I can find no direct command so should I be using raise to the power or have I missed something?
best wishes
Simon
Maths  Square Root

 Posts: 395
 Joined: Wed Nov 04, 2009 11:41 am
 Location: Gunthorpe, North Lincs, UK
Maths  Square Root
best wishes
Skids
Skids

 VIP Livecode Opensource Backer
 Posts: 1686
 Joined: Thu Feb 28, 2013 11:52 pm
 Location: Göttingen, DE
Re: Maths  Square Root
There is no "sqrt(x)" in LCB. Instead use
x^0.5 or exp(0.5*ln(x)) for 0<=x.
[The case a=0 is included in the definition of a^b := exp(b*ln(a)).]
x^0.5 or exp(0.5*ln(x)) for 0<=x.
[The case a=0 is included in the definition of a^b := exp(b*ln(a)).]
shiftLock happens

 Posts: 395
 Joined: Wed Nov 04, 2009 11:41 am
 Location: Gunthorpe, North Lincs, UK
Re: Maths  Square Root
I'll take your word on that![The case a=0 is included in the definition of a^b := exp(b*ln(a)).]
Thanks.
best wishes
Skids
Skids

 VIP Livecode Opensource Backer
 Posts: 583
 Joined: Wed Nov 22, 2006 3:42 pm
 Location: France
 Contact:
Re: Maths  Square Root
You canSimon Knight wrote: I'll take your word on that!
[hh] has a serious computer and maths background!
Regards,
Thierry
Thierry Douez  https://sunnytdz.com
Pourquoi tant de notes lorsqu'il suffit de jouer les plus belles... [Barbara]
Pourquoi tant de notes lorsqu'il suffit de jouer les plus belles... [Barbara]

 Posts: 395
 Joined: Wed Nov 04, 2009 11:41 am
 Location: Gunthorpe, North Lincs, UK
Re: Maths  Square Root
I guessed he had.
My school boy maths just does not cut it.
My school boy maths just does not cut it.
best wishes
Skids
Skids

 VIP Livecode Opensource Backer
 Posts: 1686
 Joined: Thu Feb 28, 2013 11:52 pm
 Location: Göttingen, DE
Re: Maths  Square Root
To make it simple I meant with that LC computes as needed: exp(0.5*ln(0))=0The case a=0 is included in the definition of a^b := exp(b*ln(a)).
[what is the limit of exp(0.5*ln(x)) for 0 < x > 0]
The equality (extended by the limit above for x=0)
sqrt(x)=exp(0.5*ln(x)) if 0<=x
is very important for the case that the "^" key on a keyboard becomes ever defunct by frequent GPS computings
shiftLock happens
Re: Maths  Square Root
This has been added to 'develop' now: http://quality.livecode.com/show_bug.cgi?id=20079
It will be in DP9.
It will be in DP9.