FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

std.math
Goto page Previous  1, 2, 3  Next
 
Post new topic   Reply to topic     Forum Index -> Ares
View previous topic :: View next topic  
Author Message
sean



Joined: 24 Jun 2004
Posts: 609
Location: Bay Area, CA

PostPosted: Tue Jan 31, 2006 5:18 pm    Post subject: Reply with quote

kris wrote:
The D style has still to evolve. If adopted by the masses, Ares and other projects like it, will ultimately guide the stylistic cues. It's quite possible that Walter didn't even give much thought to the 'guidelines' indicated on the D website? It ain't the gospel. Heck, virtually all of it is adopted from other languages anyway Smile

As long as the decision isn't arbitrary then I'm amenable Smile My only real goal here is to have a convincing argument for any design decisions that may need explaining. Whatever happens however, I guarantee that file/directory capitalization will match the module label.
Back to top
View user's profile Send private message
Don Clugston



Joined: 05 Oct 2005
Posts: 91
Location: Germany (expat Australian)

PostPosted: Wed Feb 01, 2006 2:20 am    Post subject: Reply with quote

Quote:
This is great, but do you think it's necessary to force everything to lowercase?

I would prefer camelCase actually, but the important thing is that it is consistent. If can get rid of a few more relics from C and Fortran, that would be great.

(I notice a few people said CamelCase in their posts, I presume they meant camelCase, rather than PascalCase?)

I didn't make this clear -- the things with ? in front could belong either in std.math.ieee or std.math.core, but I've indicated the one which I think is most appropriate. (The ones like feqrel() could even be in std.math.ieee, and be pulled into std.math.core via an alias, so I'm inclined to put all such marginal cases into ieee).

The deprecation candidates have both a ? and a comment.

After a little more thought, I agree that all the special functions should be in std.math.special. Some of the bulky ones may end up in their own files and be pulled in via aliases; but it makes sense for std.math.special to be the only public "header file", and the only source for documentation.

I think it would be worth establishing a convention for such implementation files. One option would be to follow boost, and have a subdirectory called 'internal'.
Back to top
View user's profile Send private message
larsivi
Site Admin


Joined: 27 Mar 2004
Posts: 453
Location: Trondheim, Norway

PostPosted: Wed Feb 01, 2006 5:18 am    Post subject: Reply with quote

Don Clugston wrote:

(I notice a few people said CamelCase in their posts, I presume they meant camelCase, rather than PascalCase?)



AFAIK this is CamelCase and this dromedarCase Wink Anyway, the point is that the filename must be the same as the modulename, and in the case of classes , the module name often match a classname which use CamelCase. For non-class modules dromedarCase might be equally appropriate.
Back to top
View user's profile Send private message
Don Clugston



Joined: 05 Oct 2005
Posts: 91
Location: Germany (expat Australian)

PostPosted: Wed Feb 01, 2006 6:20 am    Post subject: Reply with quote

Quote:
AFAIK this is CamelCase and this dromedarCase


I'd never heard of that, but a quick google/Wikipedia search showed that:
PascalCase = UpperCamelCase = CamelCase
camelCase = lowerCamelCase = dromedaryCase

The first recorded usage of CamelCase was in 1995, and was in reference to something that started with a lower case letter ("eMpTy").

The ambiguity 'camelCase' vs 'CamelCase' is extremely unhelpful.
MS uses the terms camelCase and PascalCase.
Back to top
View user's profile Send private message
sean



Joined: 24 Jun 2004
Posts: 609
Location: Bay Area, CA

PostPosted: Wed Feb 01, 2006 10:45 am    Post subject: Reply with quote

larsivi wrote:
Don Clugston wrote:

(I notice a few people said CamelCase in their posts, I presume they meant camelCase, rather than PascalCase?)



AFAIK this is CamelCase and this dromedarCase Wink Anyway, the point is that the filename must be the same as the modulename, and in the case of classes , the module name often match a classname which use CamelCase. For non-class modules dromedarCase might be equally appropriate.

And what about modules that contain multiple classes? Or modules that contain a class of a different name? Not being much of a Java person, I don't really follow the 1-1 module to class mapping.

Another minor concern with CamelCasing module names is whether this should be done with C headers as well, or whether the original name and case variation should be preserved. I haven't been able to decide on this one, but assuming the case is left unchanged, this creates an (easily defined) exception to the CamelCase rule.

As for the CamelCase issue... how about we just use 'mixedCase' and assume it implies the rules outlined in the D style guide. The last thing this conversation needs is a discussion about livestock terminology. I'm starting to feel like we're working at O'Reilly Wink
Back to top
View user's profile Send private message
sean



Joined: 24 Jun 2004
Posts: 609
Location: Bay Area, CA

PostPosted: Wed Feb 01, 2006 3:20 pm    Post subject: Reply with quote

Okay, std.math.core, std.math.ieee, and std.math.special are done. I'll probably get a new Ares release out today with them included. I ran into some name collisions in std.math.core as it imports both std.c.math and std.math.ieee, both of which define fabs, frexp, and ldexp. The calls are now explicitly mapped to the std.math.ieee implementation, but it's worth noting that importing std.c.math and std.math.ieee into the same module will cause collisions. It may be worthwhile to eventually rename the functions in one of these two modules or to namespace everything inside structs, but that's a discussion unto itself.

[edit]

Intrinsics! It appears that the intrinsics are replaced based on their decorated name, so none of them work if declarted outside std/math.d. Worse yet, DMC doesn't contain a C implementation of these either because it assumes it can inline the code. So there are some very annoying gaps in functionality under DMD at the moment (sqrt, cos, etc). I'm not entirely sure how to address this, though simply writing the darn code may be the most expedient. I'm of half a mind to simply ask Walter to move all intrinsics into std.intrinsic, but what he's currently doing seems entirely reasonable so I haven't been able to convince myself to do so quite yet.


Last edited by sean on Wed Feb 01, 2006 4:49 pm; edited 1 time in total
Back to top
View user's profile Send private message
lgoss007



Joined: 13 Oct 2005
Posts: 20

PostPosted: Wed Feb 01, 2006 9:53 pm    Post subject: Reply with quote

Quote:
I agree that CamelCase looks clearer, but the biggest objection has been that some platforms (all but win32 generally) are case sensitive, whereas windows ain't.


I also prefer the PascalCase (or upper CamelCase) and find it clearer as well. I don't see why people object due to platforms being case sensitive, I work on one and it's never been a problem. But anyways, I'd even go so far as to offer to convert it all to PascalCase if this would be acceptable. I gotta be useful for something Very Happy
Back to top
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger
sean



Joined: 24 Jun 2004
Posts: 609
Location: Bay Area, CA

PostPosted: Thu Feb 02, 2006 12:41 am    Post subject: Reply with quote

Just a quick update on intrinsics. I tried faking out the code generator by pre-mangling function names:
Quote:
extern (C) real D3std4math4fabsFeZe(real);
alias D3std4math4fabsFeZe fabs;

But the above still generates a link error. I'm going to continue playing with it a bit, but I'm beginning to suspect that, aside from hex editing dmd.exe, exploiting the built-in intrinsic support for these functions isn't going to work.
Back to top
View user's profile Send private message
Don Clugston



Joined: 05 Oct 2005
Posts: 91
Location: Germany (expat Australian)

PostPosted: Thu Feb 02, 2006 1:49 am    Post subject: Reply with quote

Quote:
I'm of half a mind to simply ask Walter to move all intrinsics into std.intrinsic, but what he's currently doing seems entirely reasonable so I haven't been able to convince myself to do so quite yet.


I think an ideal solution would be to extend the "extern" syntax, so that these could be declared:

extern (intrinsic) real fabs(real);

and then they could be put anywhere. For example, I think that many of the current intrinsics would be better included in something like "std.bitoperations". On different processors (and even compilers) the set of intrinsics could differ.
Having the names hard-coded is really a hack.
Back to top
View user's profile Send private message
Don Clugston



Joined: 05 Oct 2005
Posts: 91
Location: Germany (expat Australian)

PostPosted: Thu Feb 02, 2006 5:27 am    Post subject: Submission: rndint, rndlong Reply with quote

They're utterly trivial. Should really be compiler intrinsics.
--------------------------------
/**
* Rounds x to the nearest int or long.
*
* This is generally the fastest method to convert a floating-point number
* to an integer. Note that the results from this function
* depend on the rounding mode, if the fractional part of x is exactly 0.5.
* If using the default rounding mode (ties round to even integers)
* rndint(4.5) == 4, rndint(5.5)==6.
*/
int rndint(real x)
{
version(D_InlineAsm_X86) {
int n;
asm {
fld x;
fistp n;
}
return n;
} else {
return std.c.math.lrintl(x);
}
}

/** ditto */
long rndlong(real x)
{
version (D_InlineAsm_X86) {
long n;
asm {
fld x;
fistp n;
}
return n;
} else {
return std.c.math.llrintl(x);
}
}
-----------------------------
Back to top
View user's profile Send private message
sean



Joined: 24 Jun 2004
Posts: 609
Location: Bay Area, CA

PostPosted: Thu Feb 02, 2006 9:31 am    Post subject: Reply with quote

I'm not sure any special syntax should be supported for intrinsics, as they're really just a case where the compiler implementor said "you know, I can do better than the library writer here." ie. it seems a quality of implementation issue for the most part. std.intrinsic seems to be a slightly different case however as it contains functions that are intended to correspond to one machine instruction, and programmers may rely on them being extremely fast. But as a standard library is required to be arranged a certain way, that a compiler might be looking for a particular signature seems reasonable. It's only a problem here because we're trying to replace Phobos with something different.

I'll admit I don't entirely understand the point of built-in intrinsics for more general functions like sqrt, as I would think that a short function containing assember would be inlined to produce approximately the same result. Perhaps it's simply that the compiler doesn't inline assembler functions because the code may rely on the function's call stack, and expecting a library writer to write a naked assembler function is simply unreasonable?

As for the remaining missing functions, I may decompile short programs that call them (using Phobos) and extract the code into asm blocks as well. Hopefully this will produce a DMD compatible implementation for each without much hassle.
Back to top
View user's profile Send private message
Don Clugston



Joined: 05 Oct 2005
Posts: 91
Location: Germany (expat Australian)

PostPosted: Thu Feb 02, 2006 10:34 am    Post subject: Reply with quote

Quote:
I'll admit I don't entirely understand the point of built-in intrinsics for more general functions like sqrt,


inline real sqrt(real x)
asm {
FSQRT;
}
}

You're probably right about this being a problem unique to the current situation. Still, I don't think that user code should ever include an import of std.intrinsic; being intrinsic or not is an implementation detail. std.intrinsic should disappear in the long term.
Back to top
View user's profile Send private message
sean



Joined: 24 Jun 2004
Posts: 609
Location: Bay Area, CA

PostPosted: Thu Feb 02, 2006 4:09 pm    Post subject: Reply with quote

Don Clugston wrote:
Quote:
I'll admit I don't entirely understand the point of built-in intrinsics for more general functions like sqrt,


inline real sqrt(real x)
asm {
FSQRT;
}
}

That's what I get for being unfamiliar with the floating-point instruction set Wink Seems it will be easier than I thought to get this stuff into the next release.
Quote:
You're probably right about this being a problem unique to the current situation. Still, I don't think that user code should ever include an import of std.intrinsic; being intrinsic or not is an implementation detail. std.intrinsic should disappear in the long term.

This is a good point. The easiest approach from Walter's perspective would be to simply add the prototypes to object.d and fix the decorated names in the back-end code. Thus no need for explicit inclusion but the basic approach could remain the same. It would probably take longer to fix the documentation than it would the compiler code.
Back to top
View user's profile Send private message
sean



Joined: 24 Jun 2004
Posts: 609
Location: Bay Area, CA

PostPosted: Thu Feb 02, 2006 10:24 pm    Post subject: Reply with quote

Done and done. The intrinsics now have inline asm implementations and I've altered the rounding functions as described above.
Back to top
View user's profile Send private message
kris



Joined: 27 Mar 2004
Posts: 1494
Location: South Pacific

PostPosted: Thu Feb 02, 2006 10:50 pm    Post subject: Reply with quote

sean wrote:
Done and done. The intrinsics now have inline asm implementations and I've altered the rounding functions as described above.

Interesting! Does the compiler actually inline them optimally?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> Ares All times are GMT - 6 Hours
Goto page Previous  1, 2, 3  Next
Page 2 of 3

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group