Discussion:
OBNC Out.Real
(too old to reply)
Hưng Gia
2020-03-06 07:48:22 UTC
Permalink
Could you adjust the behavior of it to print normal floating point number instead of scientific notation? If it's the your design could you provide a way to print floating point number in the normal format? I can't found any procedure to it. I tried to use your ext library to convert real to string but it didn't work. The procedure take three parameters and not suitable to use like what I desire:

Out.String(extConvert.RealToString(Math.sqrt(2)));
Guy T.
2020-03-07 12:36:25 UTC
Permalink
Post by HÆ°ng Gia
Out.String(extConvert.RealToString(Math.sqrt(2)));
Hello Hưng Gia,

Modifying Out.Real is not a good idea as this module is expected to supply its procedure in the way they are. It would brake many existing piece of code. Better extract some lines of code from an existing module and modify it a bit to be like you desire.


Cheers

Guy T.
miasap
2020-03-07 18:59:07 UTC
Permalink
Post by HÆ°ng Gia
Could you adjust the behavior of it to print normal floating point
number instead of scientific notation? If it's the your design could
you provide a way to print floating point number in the normal
format? I can't found any procedure to it.
As mentioned by Guy T, it's better to define a new procedure. The Out
module implements the procedure Real according to the specification in
"The Oakwood Guidelines for Oberon-2 Compiler Developers."

Below is an example of how you can interface to the C function printf
(see also the manual page for the obnc command).

MODULE Print;

(*implemented in C*)

PROCEDURE Real*(x: REAL);
END Real;

END Print.


Print.c:

#include ".obnc/Print.h"
#include <stdio.h>

void Print__Real_(OBNC_REAL x)
{
printf("%f", x);
}


void Print__Init(void)
{
}


MODULE PrintTest;

IMPORT Out, Print;

BEGIN
Print.Real(3.1415926535);
Out.Ln
END PrintTest.
Post by HÆ°ng Gia
I tried to use your ext library to convert real to string but it
didn't work. The procedure take three parameters and not suitable to
use like what I desire >
Out.String(extConvert.RealToString(Math.sqrt(2)));
In Oberon a procedure can only return scalar values. That's why
RealToString is defined the way it is. Also, the procedure uses the same
format as Out.Real.


-- Karl

Loading...