www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - core.math.rndtonl: invalid return type or description?

reply ketmar <ketmar ketmar.no-ip.org> writes:
core.math.rndtonl is declared as this:

	extern (C) real rndtonl(real x);

yet it's description says: "...If the integer value of x is greater than 
long.max, the result is indeterminate."

it looks like it either should return `long`, or this part of description 
was copypasted from `rndtol`. and if it *really* has such limitation, but 
returns `real`, i think it should be clarified in documentation, 'cause 
right now it is somewhat confusing.
Jun 19
parent reply ag0aep6g <anonymous example.com> writes:
On 06/19/2017 10:04 AM, ketmar wrote:
 core.math.rndtonl is declared as this:
 
      extern (C) real rndtonl(real x);
Is rndtonl a Digital Mars C thing? It has no implementation in druntime, and I get an undefined reference when I try to call it on Linux. It compiles on Windows (wine, -m32), but only ever returns -nan. If this is the same function: <http://www.digitalmars.com/rtl/fltpnt.html#rndtol>, then it should return a C long, which I guess is a D int on 32 bits. And surprise: that works.
Jun 19
next sibling parent reply ketmar <ketmar ketmar.no-ip.org> writes:
ag0aep6g wrote:

 On 06/19/2017 10:04 AM, ketmar wrote:
 core.math.rndtonl is declared as this:
 extern (C) real rndtonl(real x);
Is rndtonl a Digital Mars C thing?
yes, it looks like DMC library function. thus, is should be versioned out on non-DMC builds. another bug. ;-)
 It has no implementation in druntime, and I get an undefined reference  
 when I try to call it on Linux.

 It compiles on Windows (wine, -m32), but only ever returns -nan.
 If this is the same function: 
 <http://www.digitalmars.com/rtl/fltpnt.html#rndtol>, then it should 
 return a C long, which I guess is a D int on 32 bits. And surprise: that 
 works.
no, there is `rndtol()` and `rndtonl()` in `core.math`, they are different functions. also, `rndtol()` should return D `long` (i.e. 64 bit value). at least this is what `core.math` says.
Jun 19
parent reply ag0aep6g <anonymous example.com> writes:
On 06/19/2017 12:45 PM, ketmar wrote:
 ag0aep6g wrote:
[...]
 If this is the same function: 
 <http://www.digitalmars.com/rtl/fltpnt.html#rndtol>, then it should 
 return a C long, which I guess is a D int on 32 bits. And surprise: 
 that works.
no, there is `rndtol()` and `rndtonl()` in `core.math`, they are different functions.
The link covers both. See the Prototype and Description sections.
 also, `rndtol()` should return D `long` (i.e. 64 bit value). at least 
 this is what `core.math` says.
Sure, but it doesn't work with D long. It works with D int, which makes sense when the function actually returns a C long (assuming that DMC's long has 32 bits).
Jun 19
parent ketmar <ketmar ketmar.no-ip.org> writes:
ag0aep6g wrote:

 On 06/19/2017 12:45 PM, ketmar wrote:
 ag0aep6g wrote:
[...]
 If this is the same function: 
 <http://www.digitalmars.com/rtl/fltpnt.html#rndtol>, then it should 
 return a C long, which I guess is a D int on 32 bits. And surprise: 
 that works.
no, there is `rndtol()` and `rndtonl()` in `core.math`, they are different functions.
The link covers both. See the Prototype and Description sections.
ah, sorry, i should really read linked text instead of guessing from the name only. ;-)
 also, `rndtol()` should return D `long` (i.e. 64 bit value). at least 
 this is what `core.math` says.
Sure, but it doesn't work with D long. It works with D int, which makes sense when the function actually returns a C long (assuming that DMC's long has 32 bits).
then it is yet another bug in `core.math`...
Jun 19
prev sibling parent ketmar <ketmar ketmar.no-ip.org> writes:
p.s.: it is *important* to use `core.math.rndtonl`! this is compiler 
intrinsic (or at least it should be), and it won't be detected as intrinsic 
outside of `core.math`.
Jun 19