LibreOffice Calc basic seems to have just one inverse trig function, “atn” for arctan.
arcsin and arccos etc, or their equivalents, seem to unavailable.
Suggestions welcomed
LibreOffice Calc basic seems to have just one inverse trig function, “atn” for arctan.
arcsin and arccos etc, or their equivalents, seem to unavailable.
Suggestions welcomed
They are , in fact, the names of the functions that are missing from LibreOffice Basic.
Version: 7.4.1.2 (x64) / LibreOffice Community
BASIC runtime error
Sub-procedure or function procedure not defined
Above is the error message I get when i try asin() or acos()
The link you kindly provided is only relevent to spreadsheet functions, not macros written with basic.
It seems weird to me that they are missing.
I am upgrading to LibreOffice 7.6. Maybe I will find them there.
Ah, I missed the word Basic in your post, apologies.
However, perhaps Using Calc Functions in Macros - LibreOffice may be of some help to you in the future.
It’s very strange not having them available. Imagine a calculator without those functions. There must be reasons. Maybe the estate of Archimedes has a claim on them. Who knows.
StarBasic is not a calculator.
See the "Useful identities if one only has a fragment of a sine table: " part of this site:
Stop panicking, everyone. Wikepedia came to the rescue. This is what I did
Function asin(x)
asin = 2*atn((x/(1 + sqr(1-x^2))))
End Function
Function acos(x)
acos = 2*atn(sqr(1 - x^2)/(1 + x))
End Function
I’ll test their accuracy next time I sail my yacht around the world.
That, too, is useful.
You can used Python and call from Basic too:
import math
def pyasin(x):
return math.asin(x)
then
Function pyasin(x)
pyasin = callPythonScript("pyasin", x)
End Function
Public Function callPythonScript(macro As String, arg)
GlobalScope.BasicLibraries.LoadLibrary("ScriptForge")
session = CreateScriptService("Session")
script = "mymacros.py$" & macro
result = session.ExecutePythonScript(session.SCRIPTISPERSONAL, script, arg)
callPythonScript = result
End Function
LibO (Star-, OO.o-, AOO-) Basic dont “have” these functions, but you don’t need to change to a different programming langue (with those functions probably specified differently as compared to the respective Calc functions - and surely lacking other Calc functions).
There is the LibO API providing a service allowing you to call any function available in Calc also from user code in any supported language, and independent of what kind of LibO document is active.
The service is named com.sun.star.sheet.FunctionAcces
and an instance is created in Basic code by
myFAservice = CreateUNOService("com.sun.star.sheet.FunctionAcces")
where the name of the variable is freely chosen, of course.
A call to the arctan function would then look like (e.g.):
neededVal = myFAservice.callFunction("ATAN", Array(1))
If you need such calls often, you can follow my suggestions to find here.
As a first example you may try then
pAMQ4ByDeg = gCallCalcFunction("ATAN2", Array(1, -1))/Pi() * 180
How do I make it look like v = atan2(y,x)?
One shouldn’t have to be a software engineer to implement such elementary mathematical functions. I mean no reflections upon your good self, Lupp. I do appreciate your knowledge
How should I read this as a “suggested solution”? It’s a comment on my suggestion.
Functions that are implemented for Calc but not (with the exactly same meaning) for Basic can be called the way I described. To do it this way you don’t need any special knowledge - except how to use the LibO API in principle. This fundamental knowledge may be needed in next to every case of writing user code for LibO.
See
disask100381demoForComment.ods (24.7 KB)
…
I don’t know your concept of who may be called a “software engineer”. I’m none.
Anyway: This is a site to ask. And to get answers or suggestions if contributors know some.
If you think LibreOffice should get fixed a bug or get implemented new features (like the availability of functions you miss in LibO Basic), you need to post a report or a request to bugs.documentfoundation.org.