[M3devel] Possible Bug?

Mika Nystrom mika at async.caltech.edu
Wed May 6 04:24:31 CEST 2009


I don't think it's particularly hard to find...?  The interface I
almost always use is "Math.i3" and it has things like this in it:

<*EXTERNAL*> PROCEDURE sqrt (x: LONGREAL): LONGREAL;
(* returns the square root of x. *)

I think you get pretty good performance with that.

If you want speed on x86, you code in f77 and use Intel's ifort
(-sse2, or whatever hardware you have in your machine).  You can
get it free for Linux.  I compile -S on Linux and then use GNU as
on FreeBSD to get my objects.  It's really easy to link that code
with M3 if you want to do that.  All you have to remember is that
all the arrays are transposed and in Fortran they start from 1, of
course.  Then you just pass ADR(a[0,..,0]) to the f77 code.

But my experience has been that Modula-3 code really doesn't perform
that poorly on numerical work.  If you turn on optimization, that
is.
 
    Mika



Jay writes:
>
>I suggest we provide Cmath.i3 and/or Cfloat.i3 to provide trivial portable wrappers to some of this stuff in an easier to find location instead of buried. Granted, the buriers were trying to make things bette
>r in their way.
> 
> 
>And by portable, I'd limit myself probably to
>double foo(double);
> 
> 
>and not likely delve into single precision functions, unless maybe
>float foof(float) is fairly portable.
> 
>Eh, since they'd all be external, you can delcare them all and not necessarily implement all of them.
> 
> 
>In any case the perf might stink compared to C.
>Visual C++ for example can generate FPU instructions inline such as for sqrt.
>gcc probably does a good job here too.
>We'll likely incur function calls for portability.
> 
> 
>Imho we need to do better with keeping up with "builtin functions" that C compilers gradually accrue and implement very well.
>It is difficult though, for reasons of portability.
> 
> 
> - Jay
>
>----------------------------------------
>> From: jay.krell at cornell.edu
>> To: martinbishop at bellsouth.net; m3devel at elegosoft.com
>> Subject: RE: [M3devel] Possible Bug?
>> Date: Wed, 6 May 2009 01:31:29 +0000
>>
>>
>> This has never worked on most platforms.
>> We even deliberately stopped it working where it did -- e.g. SPARC.
>> We could fix it maybe.
>>
>>
>> Please try RealFloat.sqrt instead.
>>
>>
>> It is almost the same thing, but for lack of ability to use single precision, and is likely to be much much faster (how common is hardware sqrt? Anyway, vendor software sqrt is presumably excellent).
>>
>>
>> In future please give callstacks.
>> Run it under gdb or dbx, etc.
>>
>>
>> - Jay
>>
>>
>>
>> ----------------------------------------
>>> Date: Tue, 5 May 2009 19:57:43 -0500
>>> From: martinbishop at bellsouth.net
>>> To: m3devel at elegosoft.com
>>> Subject: [M3devel] Possible Bug?
>>>
>>> I have this code, for finding the roots of a quadratic equation:
>>>
>>> MODULE Quad EXPORTS Main;
>>>
>>> IMPORT IO, Fmt, RealSqrt;
>>>
>>> TYPE Roots = ARRAY [1..2] OF REAL;
>>>
>>> VAR r: Roots;
>>>
>>> PROCEDURE Solve(a, b, c: REAL): Roots =
>>> VAR sd: REAL := RealSqrt.Sqrt(b * b - 4.0 * a * c);
>>> x: REAL;
>>> BEGIN
>>> IF b < 0.0 THEN
>>> x := (-b + sd) / 2.0 * a;
>>> RETURN Roots{x, c / (a * x)};
>>> ELSE
>>> x := (-b - sd) / 2.0 * a;
>>> RETURN Roots{c / (a * x), x};
>>> END;
>>> END Solve;
>>>
>>> BEGIN
>>> r := Solve(1.0, -10.0E5, 1.0);
>>> IO.Put("X1 = " & Fmt.Real(r[1]) & " X2 = " & Fmt.Real(r[2]) & "\n");
>>> END Quad.
>>>
>>> When I try to build it, I get:
>>>
>>> ***
>>> *** runtime error:
>>> *** failed: FloatMode.SetRounding not implemented
>>> *** file "../src/float/IEEE-default/FloatMode.m3", line 14
>>> ***
>>>
>>> Aborted
>>>
>>>
>>> I'm using:
>>>
>>> martin at thinkpad:~/Code/Modula-3/Test$ cm3 -version
>>> Critical Mass Modula-3 version d5.7.1
>>> last updated: 2009-01-21
>>> compiled: 2009-04-01 13:11:43
>>> configuration: /usr/local/bin/cm3.cfg
>>>
>>> which was installed from Jay's "std" binary package.



More information about the M3devel mailing list