Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

D*

Member

05-20-2015 11:31 PM

Options

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report to a Moderator

I need to let the user enter in a custom formula via text string. (So Formula Node and Expression Node will not help me). The formula will then be evaluated via Eval Multi-Variable Scalar.vi.

The user's formula will often need the modulus operator (usually shown as % sometimes as mod(x,y), where we calculate the remainder after division of one number by another). This help file says that the mod(x,y) is not available, but I see % in the list here. Please tell me that modulus should be supported, and this is just a bug!

Solved! Go to Solution.

RavensFan

Knight of NI

05-20-2015 11:48 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report to a Moderator

Try it and find out.

TYtanic

NI Employee (retired)

05-21-2015 01:52 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report to a Moderator

Hey D,

It doesn't look like % works as modulus in the Eval Multi-Variable Scalar VI. It appears to give you a wrong variable error.

Ty Prather

Technical Marketing Specialist

National Instruments

Technical Marketing Specialist

National Instruments

rolfk

Knight of NI

05-22-2015 05:28 AM - edited 05-22-2015 05:31 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report to a Moderator

Your title talks about Evaluate Formula VIs bt your link is about the Formula Node. That are two completely different things. The Evaluate Formule Vis are written in pure LabVIEW diagram code and parse a string to do some formula evalution. It's written somewhat chaotic and supports a certain functionality that is pretty limited but since it is in pure LabVIEW code it could be extended by you. You can checkout what it can do by driling down into the subVIs and checking out the implementation. If you had done this, you would have seen that it does not support the modulus operator out of the box, but it is possible to modify it to do so. However I have to admit that its implementation is pretty dirty, inefficient and limited.

The Formula Node evaluates a script by passing the entire string to a LabVIEW internal parser/evaluator engine. It supports a larger set of functionality but requires the formula/script to be known at the time of the VI editing and therefore can't be changed at runtime.

05-22-2015 10:41 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report to a Moderator

So it *is *a bug! Can you set a CAR?

05-22-2015 10:48 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report to a Moderator

@ Rolfk, wow. That's some hairy looking innards.

I'm surprised that there are two parsers, doing essentially the same thing. Especially since you would expect the "Eval Formula Node.vi" to be able to evaluate what is in a Formula Node structure, and not run the less-capable "Evaluate Formula VIs" code.

rolfk

Knight of NI

05-22-2015 04:01 PM - edited 05-22-2015 04:03 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report to a Moderator

@D* wrote:

@ Rolfk, wow. That's some hairy looking innards.

I'm surprised that there are two parsers, doing essentially the same thing. Especially since you would expect the "Eval Formula Node.vi" to be able to evaluate what is in a Formula Node structure, and not run the less-capable "Evaluate Formula VIs" code.

It's for historical reasons. Originally the Formula Node in LabVIEW was pretty limited with a syntax that was neither C like, nor anything else, no support for arrays nor many other things. Then someone developed a Math Toolkit and one part of it was the Evaluate Formula Parser library. At some point around LabVIEW 6.0 the Formula Node got a complete work over where it was implementing a mostly C like syntax with most mathematical operators like in C. The Evaluate Formula Parser was together with many other things integrated into LabVIEW from the separate Toolkit too. Of course NI could go and throw the entire Evaluate Formula Parser library completely outt of the window and reimplement it in a cleaner and more functional way BUT....

There are many applications that have been developed in the last 15 years or so that depend on the Evaluate Formula Parser functionality as it is now, even if it is less than perfect. Changing this library now would be causing a lot of problems for those people when they upgrade. Adding yet another formula parser to LabVIEW is also not ideal, as you have already three which come with LabVIEW if you also count the MathScript node.

So, yes it is not ideal as it is, but changing it wouldn't make the situation necessarily better for many existing users, so spending resources for this is not a high priority.

I did at some point reimplement the Evaluate Formula Parser completely with a more efficient parser and evaluator component, but the actual diagram code didn't get easier to understand and I really doubt that someone else than me could easily extend it with new functionality. Formula parsing is a pretty dirty business if you want to make the parser follow the normal user expectations of formula expression and operator precedence rather than force him into some more obscure formula expressions like strict RPN notation or similar.

rolfk

Knight of NI

05-23-2015 08:45 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report to a Moderator

05-25-2015 10:46 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report to a Moderator

Solution

Accepted by topic author D*

Porter

Member

12-21-2017 10:17 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report to a Moderator

I suggest using muParser instead of trying to re-write the entire formula parsing library.

It is open source and it is pretty easy to add functions, constants, and operators if needed.

I've released a LabVIEW API for it here: https://lavag.org/files/file/295-lv-muparser/