Ask Your Question
0

How to use math functions in the Calc Basic?

asked 2016-07-19 18:15:03 +0200

Adobe gravatar image

updated 2016-07-19 18:17:44 +0200

The documentations shows how to implement a basic VOL function:

Function VOL(a, b, c)
VOL = a*b*c
End Function

So that I can write

=VOL(1,2,3)

in a spreadsheet and get 6.

I want to write arctan which would return result in degrees instead of radians:

Function ARCTAN(rad)
ARCTAN = ATAN(rad)*180/PI()
End Function

and call it as, e.g.:

=ARCTAN(1)

This doesn't work: Calc complains:

Sub-procedure or function procedure not defined

Can you help me to write this function?

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
1

answered 2016-07-19 20:49:26 +0200

Regina gravatar image

In this special case, you can use the internal functions of Basic. For a list of these functions see Alphabetic List of Functions, Statements and Operators in section Command Reference in tab Contents of the Help.

Your function might read

function ARCTAN(rad as double) as double
   ARCTAN = atn(rad)*45.0/atn(1)
end function

You need 45.0/atn(1) instead of 180.0/PI(), because PI() is not available as Basic-internal function.

edit flag offensive delete link more

Comments

PI() is not available but Pi works: ARCTAN = atn(rad) * 180 / Pi. Thanks!

Adobe gravatar imageAdobe ( 2016-07-19 22:50:53 +0200 )edit

Here's a list of most used math functions: atn/sin/cos/tan/exp/log/sqr/abs plus a constant Pi. Source.

Adobe gravatar imageAdobe ( 2016-07-19 23:16:55 +0200 )edit

Original function does work in LO v5.1.3.2 the only difference from original question being atn() vs ATAN() and this thanks to @Regina.

Also in this versions' off line Help, start with Content tab then Macros and Programming, Command Reference and finally Alphabetic List of Functions, Statements and Operators

Pi is actually used in the help example.

Changed "Answer' to "Comment" - posted just for Help reference.

Ratslinger gravatar imageRatslinger ( 2016-07-19 23:38:01 +0200 )edit
1

answered 2016-07-19 19:06:52 +0200

peterwt gravatar image

See posting here.

edit flag offensive delete link more

Comments

Thanks. The example you linked is more of a [currying])(https://en.wikipedia.org/wiki/Currying) though.

Adobe gravatar imageAdobe ( 2016-07-19 23:20:33 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2016-07-19 18:15:03 +0200

Seen: 1,371 times

Last updated: Jul 19 '16