News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

complex mathematical expression and re-used of script

Started by TouEnMasm, April 15, 2013, 04:52:19 PM

Previous topic - Next topic

TouEnMasm

This one is a translate of a c++ sample.
It show how to use the javascript function "eval".
It use the windows function ShowHTMLDialog to run the script in a HTML page.
Further samples of complex mathematical expression  are given (4)

This can be done also writing a script .js.
evalue.js:
Quote
mydate = eval(-1 * (((3*2) + 1) / 0.528 + (2.225>>1) +   ((25.24/0x03) + (12.26/1.22))));
WScript.Echo (mydate);

I have made it better.
     Added:
     -Control of the number of parenthesis
     -Syntax case is unsensitive for the javascript Object Math
     - allow instructions without Math.

Quote
db "E",0,"PI",0"abs",0,"ceil",0,"floor",0,"round",0,"max",0,"min",0
        db "pow",0,"random",0,"sqrt",0,"exp",0,"LN2",0,"LN10",0,"log",0
       db "LOG2E",0,"SQRT1_2",0,"SQRT2",0,"sin",0,"asin",0,"cos",0,"acos",0
        db "tan",0,"atan",0,0

Note:Only Jwasm (last version) could compile this source

The very classic sample:

/*  ax²+bx+c = 0 */

var a = 8
var b = 10
var c = 3
var delta = pow(b,2) -4*a*c


if (delta > 0)  {
var sola = (- b - sqrt(delta))/4;
var solb = (- b + sqrt(delta))/4;
sola + "  " +solb +"   two  soluces"
}

if (delta == 0) {
var sola = - b/(2*a);
sola + "One soluce"
}

if (delta < 0) {
"No soluce";}


Fa is a musical note to play with CL

qWord

really nice  :icon14:

For an general purpose evaluator, I would make a string replacement thus we can, for example, directly write sin() instead of Math.sin().

MREAL macros - when you need floating point arithmetic while assembling!

dedndave

very cool, Yves
i didn't know you could do that   :t

Gunther

You have to know the facts before you can distort them.

jj2007

Quote from: dedndave on April 16, 2013, 12:41:02 AM
very cool, Yves
i didn't know you could do that   :t

I didn't know it was possible - nice idea :t
Yves & Edgar are our COM champions ;-)

TouEnMasm


For replacement as:
Quote
directly write sin() instead of Math.sin().
It is possible,just put the samples here,I will add the needed proc to do it.
Fa is a musical note to play with CL

jj2007

By the way, what is "IMoniker Release"? A macro? Necessary for a local variable?

TouEnMasm

Quote
what is "IMoniker Release"?

IMoniker is an interface and as all com object had a pointer on it.
Here it's ppvIMoniker.
Get it by CreateURLMoniker.
This interface is used only by ShowHTMLDialogd.
When it is done "Release" the pointer and uninitialise  all things (memory ..)needed by the interface (if number of user =0).

The sdk translate use a very formal syntax to work with interface.
if the name of the interface is IMoniker
                   The name of the pointer is:                   ppvIMoniker
                   The name of structure of functions is:     STIMoniker
                   The invoke statement is named            IMoniker (a macro)

IMoniker Release mean:
Invoke the Release function of the IMoniker Interface

In case of there is need of a second pointer on the same interface (WMI use that)
The sdk translate provide the COM Macro (translate.inc) to solve that.






Fa is a musical note to play with CL

MichaelW

This would be more useful with an exponentiation operator.
Well Microsoft, here's another nice mess you've gotten us into.

jj2007

Where is that one defined, Yves?

error LNK2001: unresolved external symbol _ShowHTMLDialog@20

Did anybody succeed in building the example??

TouEnMasm

Quote
error LNK2001: unresolved external symbol _ShowHTMLDialog@20

The batch is named jwasm_build with a good reason,ml made this error.
Compile the sample with JWASM and all is good.
Fa is a musical note to play with CL

jj2007

Quote from: ToutEnMasm on April 16, 2013, 08:44:00 PM
Compile the sample with JWASM and all is good.

I got it running with the latest JWasm version :t

It throws a warning for line 685 of propidl.sdk:
IFDEF def __cplusplus
ELSE
ENDIF

Even with a fixed propidl, masm 8.0 + 9.0 throw exceptions ("internal error"), which is surprising for such a short code (I use version 7 of your SDK).

As you know, I am a great fan of JWasm, but IMHO a library should remain compatible to standard Masm, too. "All is good" looks different ;-)

By the way, your site is a bit difficult to access. Maybe you should put a fat text with a link to the SDK download. And you probably meant "Utilisez JWasm", not "Utilisé JWASM".

P.S.:
Quote from: jj2007 on April 16, 2013, 04:43:09 AM
By the way, what is "IMoniker Release"? A macro? Necessary for a local variable?

ObjIdl.sdk, line 1228:

IMoniker MACRO  Function:REQ, args:VARARG

TouEnMasm


If you want to play a little with bug (very funny  :icon_mrgreen:)
Try this
Math.pi;
Instead of
Quote
Math.PI;
correct syntax
This made an int 3 in

invoke SysFreeString,ebx     ;FreeBSTR PROC in bstr.inc

I search a way to avoid this.





Fa is a musical note to play with CL

TouEnMasm


For the bug just delet this line
      ;invoke VariantClear,addr varArgs            
Fa is a musical note to play with CL

Siekmanski

Creative coders use backward thinking techniques as a strategy.