www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - std.math "is" functions

reply "Miguel F. Simões" <Kobold netcabo.pt> writes:
This is not really a bug...
I am not sure if the functions that belong to std.math and start with "is"
(isnan, isfinite, isnormal, issubnormal) are supposed to return an int.

In my humble opinion, we are testing a boolean condition.

-- 
Miguel Ferreira Simões 
Apr 16 2005
parent reply =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> writes:
Miguel F. Simões wrote:

 This is not really a bug...
 I am not sure if the functions that belong to std.math and start with "is"
 (isnan, isfinite, isnormal, issubnormal) are supposed to return an int.
 
 In my humble opinion, we are testing a boolean condition.
D does not have booleans. Thus, it can return either bit or byte or int. (but I agree with you, it probably *should* be "bool"... It just isn't?) --anders PS. See also "int opEquals(Object o);" in Object. It returns true/false too.
Apr 16 2005
parent reply "Ben Hinkle" <ben.hinkle gmail.com> writes:
"Anders F Björklund" <afb algonet.se> wrote in message 
news:d3qpei$2gvq$1 digitaldaemon.com...
 Miguel F. Simões wrote:

 This is not really a bug...
 I am not sure if the functions that belong to std.math and start with 
 "is"
 (isnan, isfinite, isnormal, issubnormal) are supposed to return an int.

 In my humble opinion, we are testing a boolean condition.
D does not have booleans. Thus, it can return either bit or byte or int.
oh Anders, 'bit' really doesn't sit well with you, eh? The poor guy probably didn't realize what a natural question involving boolean can touch off around here :-) Some functions return int because 'if' conditionals can accept ints and there is a performance penalty (probably small but I don't know) involved with converting an int to a bit (aka bool). I don't know what the impact of returning bool would be on the performance of isnan and friends. I think it would be worth investigating.
 (but I agree with you, it probably *should* be "bool"... It just isn't?)

 --anders

 PS.
 See also "int opEquals(Object o);" in Object. It returns true/false too.
Apr 16 2005
next sibling parent =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> writes:
Ben Hinkle wrote:

In my humble opinion, we are testing a boolean condition.
D does not have booleans. Thus, it can return either bit or byte or int.
oh Anders, 'bit' really doesn't sit well with you, eh?
Nope. But I usually try to constrain myself better... :-) It's better than _Bool, though ? (that C99 calls it)
 The poor guy probably didn't realize what a natural question
 involving boolean can touch off around here :-)
It's a natural question. And the"natural" answer is that neither C nor D *have* a boolean type, just integers... This will continue to come up. That's why I wrote: http://www.prowiki.org/wiki4d/wiki.cgi?BitsAndBools
 Some functions return int because 'if' conditionals can accept ints and 
 there is a performance penalty (probably small but I don't know) involved 
 with converting an int to a bit (aka bool). I don't know what the impact of 
 returning bool would be on the performance of isnan and friends. I think it 
 would be worth investigating.
byte is smaller/slower, int is larger/faster - that's pretty well-known. C++ chose the route of not fixing the boolean type size, D set it at 1. I'm not sure the gained performance is worth the confusion, but anyway. In Altivec, they are called "bool char", "bool short" and "bool int" ? (i.e. "bool" is a prefix there, just there is an "unsigned" as usual). bit is a strange pseudo-boolean hybrid, neither integer nor boolean... I'm sure it will continue to surprise D users, for many years to come. --anders
Apr 16 2005
prev sibling parent reply "Miguel Ferreira Simões" <Kobold netcabo.pt> writes:
 Some functions return int because 'if' conditionals can accept ints and 
 there is a performance penalty (probably small but I don't know) involved 
 with converting an int to a bit (aka bool). I don't know what the impact 
 of returning bool would be on the performance of isnan and friends. I 
 think it would be worth investigating.
I am getting a little confused... The reason that led me to raise this issue... was a warning caused by a conditional statement that did not accept bools! But I guess it should be allowed. Thanks. Miguel
Apr 16 2005
parent reply "Ben Hinkle" <ben.hinkle gmail.com> writes:
"Miguel Ferreira Simões" <Kobold netcabo.pt> wrote in message 
news:d3sj8t$pt1$1 digitaldaemon.com...
 Some functions return int because 'if' conditionals can accept ints and 
 there is a performance penalty (probably small but I don't know) involved 
 with converting an int to a bit (aka bool). I don't know what the impact 
 of returning bool would be on the performance of isnan and friends. I 
 think it would be worth investigating.
I am getting a little confused... The reason that led me to raise this issue... was a warning caused by a conditional statement that did not accept bools! But I guess it should be allowed.
That sounds like a problem. Can you reproduce the warning? Maybe it was warning about casting to int to bool? That happens all the time and it IMO makes the -w option the dmd pretty useless. Whenever I try -w it stops on the first warning and refuses to keep going.
Apr 16 2005
parent Derek Parnell <derek psych.ward> writes:
On Sun, 17 Apr 2005 00:59:15 -0400, Ben Hinkle wrote:


[snip]
 Maybe it was 
 warning about casting to int to bool? That happens all the time and it IMO 
 makes the -w option the dmd pretty useless. Whenever I try -w it stops on 
 the first warning and refuses to keep going.
I find that the -w switch is very useful. Its implementation also very annoying in that it stops after only a few warnings have been displayed. Annoying because it slows down the process of fixing up the code. But it is still useful in that I can at least find suspect code using -w. -- Derek Parnell Melbourne, Australia 17/04/2005 3:25:05 PM
Apr 16 2005