[Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register]

Author Message
catkin
Power User

Joined: 03 Feb 2007
Posts: 83

 Posted: Sat Feb 03, 2007 11:23 pm    Post subject: What exactly is a "numeric expression"? Hello What exactly is a "numeric expression"? There are many references to it but I can't find a definitive description. Best Charles
noranthon
Super User

Joined: 07 Jul 2005
Posts: 3318

 Posted: Sun Feb 04, 2007 3:37 am    Post subject: I think your question is too vague. Where is that phrase used? Are you talking about the API or StarBasic, Java, what? IsNumeric seems to mean the same as Calc's ISNUMBER. FWIW, Wikipedia has no page on the phrase. Answers.com has a number of references._________________ search forum by month
catkin
Power User

Joined: 03 Feb 2007
Posts: 83

 Posted: Sun Feb 04, 2007 3:50 am    Post subject: Thanks for response and sorry for being imprecise. Here's an improved version: In OOo Basic, what exactly is "numeric expression"? There are many references to it in the Help but I can't find a precise description. Current uncertainties include: a) Is it constrained to the numeric size of (signed|unsigned) Integer, Long, Single, Double or Currency? b) Can it be hexadecimal? From experimentation it seems, at least some of the time, it can be, without a &H prefix. Best Charles
PromptJock
Super User

Joined: 26 Jul 2006
Posts: 741

Posted: Mon Feb 05, 2007 2:43 pm    Post subject: Re: What exactly is a "numeric expression"?

 catkin wrote: Hello What exactly is a "numeric expression"? There are many references to it but I can't find a definitive description. Best Charles

A "numeric expression" can be as simple as "a=2" and "2+2=4", or as complex as defining a Fourier transform sequence.

IOW, an "expression" can be synonymous with "formula" or "algorithm".

As already noted, without knowing "where do you want to go? what do you want to do? etc.", we can't give anything that's more in-depth.
_________________
I'm making perfect sense - you're just not keeping up!
catkin
Power User

Joined: 03 Feb 2007
Posts: 83

Posted: Tue Feb 06, 2007 11:19 pm    Post subject:

Thanks PromtJock

You've given a helpful definition of a Numeric Expression in general terms but I'm looking for a definition of what Numeric Expression means in OOo Basic syntax. Tests show that OOo Basic does not behave like C; the assignment a=2 is not taken as a Numeric Expression with value 2.

What got me started on all this was writing Hex/Decimal conversion routines for arbitrarily long integers represented as Strings.

While experimenting I became curious; what, exactly, was a Numeric Expression? I looked for the in-depth reference documentation that would give that information. Fair enough it wasn't in the online Help -- that sort of information is a bit abtruse and indigestible for everday use. Sort of weird, though, to find so many references to Numeric Expression in the online help and no definition, not even a simplistic one.

So I asked in this forum.

Here's an example to clarify what I'm looking for (this is from the Help) followed by some further test reports:
 Quote: Fix Function [Runtime] Returns the integer value of a numeric expression by removing the fractional part of the number. Syntax: Fix (Expression) Return value: Double Parameters: Expression: Numeric expression that you want to return the integer value for.
The return is of type Double so that implies that Numeric Expression cannot be numerically larger than 1.79769313486232 x 10E308.

Is 1.79769313486232E+308 a Numeric Expression? Maybe. Tested using
 Code: Print(Fix(1.79769313486232E+308))
but OOo stopped responding, using 100% CPU.

Time to switch experiments from Fix() to IsNumeric(). Presumably one definition of a Numeric Expression is "that which, when given as an argument to IsNumeric() returns True". Tested using
 Code: Print IsNumeric(1.79769313486232E+308) Print IsNumeric(1.79769313486232E+999)
and both gave True.

OK -- Numeric Expressions can represent numbers bigger than Doubles.

This next snippet should have failed but generated no error message:
 Code: Dim d As Double d=1.79769313486232E+999

Curious about what d held after running the above:
 Code: Dim d As Double d=1.79769313486232E+999 Print(d)
and OOo stopped responding, using 100% CPU.

Mmm ... experimentation will be a hard way to establish what, exactly, a Numeric Expression is and reverse engineering sucks anyway!

Back to the original question: what, exactly, is a Numeric Expression? That information must exist else how did the developers code IsNumeric()?

Best

Charles
B Marcelly
Super User

Joined: 12 May 2004
Posts: 1453
Location: France

Posted: Wed Feb 07, 2007 12:13 am    Post subject:

Hi,
OOoBasic is designed to simplify programming. I am speaking of Basic, not of the API

A fundamental facility provided by Basic is that it silently converts a value into the type needed for the current operation. For example it will convert an Integer or Long into a Single or Double value or any combination of these. Example
 Code: dim n as long, v as double v = 1234.5678 n = v - 0.3 print n

In the above code the formula v -0.3 is computed as Double.
Then the result is converted to Long and assigned to variable n.
Then the value of variable n is converted to String and the result is displayed.
If you change the formula to n = v the displayed result will be 1235
This means that Basic has rounded the value of v when converting it to Long.

Another example
 Code: dim n as long n = "  123 + 4" print n

Here you will see that the conversion process from a String to a Long consists in searching the first number in the String. Remark that Basic does not understand that it is a formula.
Basic makes auto-conversions, but cannot make miracles.

Yet another example
 Code: dim n as long n = "Sheet1" print n

The above code displays value zero. Whenever Basic cannot autoconvert to a number, the result is zero. This may hide programming errors.

Now the answer to the question : what is a Numeric expression ?
It is an expression that Basic can correctly interpret so that it can obtain a number as result. If you want something other than zero, your expression should be understandable by Basic. A numeric expression may be a number, or a formula composed of numbers, variables, functions, etc.

You may read StarOffice 8 Programmer's Guide, chapter The RunTime Library of StarOffice Basic, section Conversion Functions. Some bugs remain in this Guide, but it is a good description.
catkin
Power User

Joined: 03 Feb 2007
Posts: 83

 Posted: Wed Feb 07, 2007 2:38 am    Post subject: Hello B Thanks for the helpful and understandable reply. The conveniences and surprises of type coercion! The link to the StarOffice 8 Programmer's Guide is really useful too -- it's more thorough than the documentation I've been working with so far. Thanks again. Charles
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First
 All times are GMT - 8 Hours Page 1 of 1

 Jump to: Select a forum OpenOffice.org Forums----------------Setup and TroubleshootingOpenOffice.org WriterOpenOffice.org CalcOpenOffice.org ImpressOpenOffice.org DrawOpenOffice.org MathOpenOffice.org BaseOpenOffice.org Macros and APIOpenOffice.org Code Snippets Community Forums----------------General DiscussionSite Feedback
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum