Issue-#147 Fraction function in System Math

Merged to the master branch

Issue-#147 Fraction function in System Math

Postby Robert » Wed Feb 22, 2017 8:22 pm

For the issue see https://redmine.blackboxframework.org/issues/147.

I propose adding a new function to System Math. This function would satisfy the equation
x = Floor(x) + Fraction(x) in a similar way that the existing function Frac satisfies x = Trunc(x) + Frac(x).

The changes to Mod/Math, Mod/SMath, Docu/Math & Rsrc/Strings are in the panel below.
This has worked reliably for me for years.
Code: Select all
   PROCEDURE Fraction* (x: REAL): REAL;
   BEGIN
      (* 20, x # INF  &  x # -INF *)
      FLD(x); FLDst0; FRNDINT;
      FCOM; FSWax; SAHF; JBE4; FLD1; FSUB;
      FSUB; WAIT; RETURN TOP()
   END Fraction;


   PROCEDURE Fraction* (x: SHORTREAL): SHORTREAL;
   BEGIN
      (* 20, x # INF  &  x # -INF *)
      FLD(x); FLDst0; FRNDINT;
      FCOM; FSWax; SAHF; JBE4; FLD1; FSUB;
      FSUB; WAIT; RETURN TOP()
   END Fraction;


      PROCEDURE Fraction (x: REAL): REAL;

You could easily implement the functions Sign, Floor, Ceiling, Trunc, Frac, Fraction, and Round yourself, using the ENTIER standard function.


PROCEDURE Fraction (x: REAL): REAL
Frac is the fractional part of the argument.
The following equation holds: x = Floor(x) + Fraction(x), within the limits of 64-bit floating point arithmetic.

Pre
x # INF  &  x # -INF   20


Math.Fraction.143   Pre: x # INF  &  x # -INF
User avatar
Robert
 
Posts: 1023
Joined: Sat Sep 28, 2013 11:04 am
Location: Edinburgh, Scotland

Re: Issue-#147 Fraction function in System Math

Postby Josef Templ » Thu Feb 23, 2017 7:51 am

The only problem I see is the naming.
We would get two functions (Frac and Fraction) with similar names
where the name does not indicate which function to choose.

Can we find a more expressive name for the new function?

Just a bold idea:
Isn't the new Fraction function like a floating point MOD operation
with modulus 1?
A name such as Mod1 may then be a candidate.

- Josef
User avatar
Josef Templ
 
Posts: 2038
Joined: Tue Sep 17, 2013 6:50 am

Re: Issue-#147 Fraction function in System Math

Postby Robert » Thu Feb 23, 2017 8:43 am

Josef Templ wrote:Just a bold idea:
Isn't the new Fraction function like a floating point MOD operation
with modulus 1?
A name such as Mod1 may then be a candidate

I like it. In fact I prefer it as it is both shorter and less confusing.
User avatar
Robert
 
Posts: 1023
Joined: Sat Sep 28, 2013 11:04 am
Location: Edinburgh, Scotland

Re: Issue-#147 Fraction function in System Math

Postby Robert » Thu Feb 23, 2017 8:48 am

The last line in the window in my first post is the addition to System Strings:
Math.Fraction.143 Pre: x # INF & x # -INF

I haven't added the corresponding line for SMath. Should I?

Should we also add all the other SMath error codes? - I have not investigated this yet.
User avatar
Robert
 
Posts: 1023
Joined: Sat Sep 28, 2013 11:04 am
Location: Edinburgh, Scotland

Re: Issue-#147 Fraction function in System Math

Postby Ivan Denisov » Thu Feb 23, 2017 9:06 am

The only problem I see is the interface compatibility with 1.7. So this can not be the issue for 1.7.1.

From my point of view, we should publish 1.7.1 ASAP and then we can adopt the features like this one.
Ivan Denisov
 
Posts: 1698
Joined: Tue Sep 17, 2013 12:21 am
Location: Russia

Re: Issue-#147 Fraction function in System Math

Postby Robert » Thu Feb 23, 2017 9:11 am

Robert wrote:Should we also add all the other SMath error codes? - I have not investigated this yet.

I think we should.


Ivan - I don't understand why this proposal introduces any incompatibility.
User avatar
Robert
 
Posts: 1023
Joined: Sat Sep 28, 2013 11:04 am
Location: Edinburgh, Scotland

Re: Issue-#147 Fraction function in System Math

Postby Ivan Denisov » Thu Feb 23, 2017 9:15 am

Robert wrote:Ivan - I don't understand why this proposal introduces any incompatibility.

Extra exported procedure will change the module fingerprint, so all modules importing Math should be recompiled. This is not allowed for "patch" version.
Ivan Denisov
 
Posts: 1698
Joined: Tue Sep 17, 2013 12:21 am
Location: Russia

Re: Issue-#147 Fraction function in System Math

Postby Robert » Thu Feb 23, 2017 9:27 am

Ivan Denisov wrote:Extra exported procedure will change the module fingerprint, so all modules importing Math should be recompiled. This is not allowed for "patch" version.

Are you sure? I know that an extra exported Method will do this, but for a static procedure I don't observe a problem.
User avatar
Robert
 
Posts: 1023
Joined: Sat Sep 28, 2013 11:04 am
Location: Edinburgh, Scotland

Re: Issue-#147 Fraction function in System Math

Postby Ivan Denisov » Thu Feb 23, 2017 12:34 pm

Robert wrote:
Ivan Denisov wrote:Extra exported procedure will change the module fingerprint, so all modules importing Math should be recompiled. This is not allowed for "patch" version.

Are you sure? I know that an extra exported Method will do this, but for a static procedure I don't observe a problem.

I am not sure... if you are right, there will be no problem.
Ivan Denisov
 
Posts: 1698
Joined: Tue Sep 17, 2013 12:21 am
Location: Russia

Re: Issue-#147 Fraction function in System Math

Postby Josef Templ » Thu Feb 23, 2017 6:57 pm

Adding an exported global procedure does not introduce any incompatibility in CP.
Every exported global procedure is fingerprinted individually. There is no global module
finger print as it was used in older Oberon compilers.

- Josef
User avatar
Josef Templ
 
Posts: 2038
Joined: Tue Sep 17, 2013 6:50 am

Next

Return to Resolved (Features)

Who is online

Users browsing this forum: No registered users and 1 guest

cron