bugGNU Octave - Bugs: bug #59615, feature request for sinpi, cospi...

 
 

bug #59615: feature request for sinpi, cospi functions

Submitter:  Gazi Aliev <gazi>
Submitted:  Thu 03 Dec 2020 10:10:25 PM UTC
   
 
Category:  Octave Function Severity:  1 - Wish
Priority:  5 - Normal Item Group:  Feature Request
Status:  Fixed Assigned to:  None
Originator Name:  Gazi Open/Closed:  * Closed
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Wed 09 Dec 2020 03:39:33 AM UTC, comment #10: 

It wasn't sinpi or cospi which aren't used by any core functions yet.  Apparently the change to sind.m to improve its accuracy is the problem.

Rik <rik5>
Group administrator
Wed 09 Dec 2020 12:02:01 AM UTC, comment #9: 

it looks like it broke "test camorbit" by ~eps precision.

Dmitri.
--

Dmitri A. Sergatskov <dasergatskov>
Tue 08 Dec 2020 07:19:46 PM UTC, comment #8: 

I implemented cospi and sinpi functions in this changeset: http://hg.savannah.gnu.org/hgweb/octave/rev/b58e3a04fab3.

I'm going to mark this bug as fixed and close it.  But, a separate bug report could be opened for yyaxis.  On the other hand, it's not like we don't know that the function is missing.  It's just difficult to implement currently.

Rik <rik5>
Group administrator
Tue 08 Dec 2020 03:34:11 PM UTC, comment #7: 

I really thought there was another bug report/missing feature/wishlist item or something addressing yyaxis, but a quick search doesn't turn one up.  I thought I remembered some discussion on reworking the plotting/graphics handle backend, and things like yyaxis would be waiting on that.

maybe worth just splitting this bug into separate a sinpi/cospi bug and a yyplot missing feature/wishlist item.

Nicholas Jankowski <nrjank>
Group Member
Tue 08 Dec 2020 04:21:15 AM UTC, comment #6: 

I already have a sinpi implementation.  I'm working on adapting cospi right now. 

While implementing sinpi I found that Octave was not very accurate for large values of the input argument for sind and related functions.  In once sense, it was useful to be forced to look at this more closely.  I've already checked in a fix for sind here: http://hg.savannah.gnu.org/hgweb/octave/rev/ee20ff0ceb60.  I'll get to the other functions later.

yyaxis is going to be very difficult to implement in Octave at the moment as it relies on a dual axis graphics primitive object that Octave has no analog of.

Rik <rik5>
Group administrator
Tue 08 Dec 2020 02:28:44 AM UTC, comment #5: 

from a compatibility standpoint:

matlab apparently introduced some of these in v2018b:

sinpi
https://www.mathworks.com/help/matlab/ref/double.sinpi.html


Y = sinpi(X) computes sin(X*pi) without explicitly computing X*pi. This calculation is more accurate than sin(X*pi) because the floating-point value of pi is an approximation of π. In particular:

For integers, sinpi(n) is exactly zero.

For odd integers, sinpi(n/2) is +1 or -1.


similarly cospi
https://www.mathworks.com/help/matlab/ref/double.cospi.html

since it was mentioned in the title, yyaxis was added in 2016 and has some similarity to plotyy:
https://www.mathworks.com/help/matlab/ref/yyaxis.html

according to the help "yyaxis function creates one Axes object with two y-axes. plotyy creates two overlaid Axes objects that can get out of sync. You can use yyaxis with any 2-D plotting function. plotyy is limited to working with plotting functions of the form function(x,y). It does not work with other plotting functions, such as errorbar."

Nicholas Jankowski <nrjank>
Group Member
Sat 05 Dec 2020 01:42:42 AM UTC, comment #4: 

C11 (C language standard from 2011) added sinpi, cospi functions as an extension.  However, there hasn't been uniform pickup by C libraries.  There is no sinpi module in gnulib so we can't get it via that route.  One could have some OS-specific tests in configure.ac to try and locate these functions, but it is tedious because the functions will have different names on different platforms and it will require a chain of #ifdef/#elif#elif#endif.

The code for sind is relatively simple and I quote it here:


  I = x / 180;
  y = sin (I .* pi);
  y(I == fix (I) & isfinite (I)) = 0;


In this case, you wouldn't need to divide by 180---that is for the conversion to degrees---but you would have to add another test for half-integer multiples which must return exactly 1 or -1.  It's possible that the sin() function already has an optimization for that because I tried some multiples of pi and didn't find any result other than 1 or -1.  But, otherwise, a test like this might work.


I -= .5;
idx = I == fix (I) & isfinite (I);
y(idx) = sign (y(idx));


In C or C++ there is probably a fancy way to check for exact integers or half integers with bit operations on the mantissa.  That sort of code, however, is beyond me.

Rik <rik5>
Group administrator
Fri 04 Dec 2020 01:09:35 PM UTC, comment #3: 

I use the following

function A = sinpi(B)
A = sind(180*B)

Gazi Aliev <gazi>
Fri 04 Dec 2020 12:34:53 PM UTC, comment #2: 

Just for reference, it seems that R implements these functions
by wrapping special functions that are available on some systems.
While on other systems it falls back to using

sin(X PI) or cos (X PI)

https://stat.ethz.ch/R-manual/R-devel/library/base/html/Trig.html

For example on my system (mac OS 10.14.6) the following
works


#include <cmath>
#include <iostream>
int
main ()
{
  double x =0;
  std::cin >> x;
  std::cout << __sinpi (x) << std::endl;

  return 0;
}




Carlo de Falco <cdf>
Group Member
Fri 04 Dec 2020 04:23:12 AM UTC, comment #1: 

Octave is developed by volunteers.  If you have an interest in a particular function the fastest course may be to write the function yourself and post it here.  It can then be reviewed for correctness and style before being incorporated in to Octave.

Otherwise, implementation will depend on someone else taking an interest in the problem.  If you absolutely must have one of these functions there are options to contract a developer to specifically code the function.  See https://www.gnu.org/software/octave/support for more information.

Rik <rik5>
Group administrator
Thu 03 Dec 2020 10:10:25 PM UTC, original submission:  


Gazi Aliev <gazi>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by dasergatskov (Posted a comment)
  • -email is unavailable- added by nrjank (Posted a comment)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by cdf (Posted a comment)
  • -email is unavailable- added by mmuetzel (Updated the item)
  • -email is unavailable- added by gazi (Submitted the item)
  • -email is unavailable- added by gazi (missing functions)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 10 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2020-12-08 rik5 StatusNone Fixed
        Open/ClosedOpen Closed
        Summaryfeature request for sinpi, cospi, yyaxis functions feature request for sinpi, cospi functions
    2020-12-04 mmuetzel Release6.1.0 dev
    2020-12-04 rik5 Carbon-CopyRemoved 72865 -
    2020-12-04 rik5 Severity3 - Normal 1 - Wish
        Item GroupMatlab Compatibility Feature Request
        Operating SystemMicrosoft Windows Any
        Summarysinpi and cospi - in Matlab after r2018b and yyaxis - after r2016a; they are still not implemented in Octave feature request for sinpi, cospi, yyaxis functions
    2020-12-03 gazi Carbon-Copy- Added -email is unavailable-

    Back to the top

    Powered by Savane 3.13-bb6a.
    Corresponding source code