Float to string with more digits?

2015-02-24 Thread Almighty Bob via Digitalmars-d-learn
Is there a more accurate way to do a float and or double to string than... to!string(float); As that seems to limit itself to 6 digits.

Re: Float to string with more digits?

2015-02-24 Thread Almighty Bob via Digitalmars-d-learn
On Tuesday, 24 February 2015 at 20:08:55 UTC, Justin Whear wrote: On Tue, 24 Feb 2015 20:04:04 +, Almighty Bob wrote: Is there a more accurate way to do a float and or double to string than... to!string(float); As that seems to limit itself to 6 digits. Use std.string.format or

Re: Float to string with more digits?

2015-02-24 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Feb 24, 2015 at 08:04:04PM +, Almighty Bob via Digitalmars-d-learn wrote: Is there a more accurate way to do a float and or double to string than... to!string(float); As that seems to limit itself to 6 digits. What about std.format.format(%.12f, myFloat)? Or, if you like:

Re: Float to string with more digits?

2015-02-24 Thread Justin Whear via Digitalmars-d-learn
On Tue, 24 Feb 2015 20:04:04 +, Almighty Bob wrote: Is there a more accurate way to do a float and or double to string than... to!string(float); As that seems to limit itself to 6 digits. Use std.string.format or std.format.formattedWrite. std.format contains a description of the

Re: Float to string with more digits?

2015-02-24 Thread Almighty Bob via Digitalmars-d-learn
Just to clarify what i needed was... %.8g or %.7e Significant digits, or fixed width scientific form. I needed more significant digits. %.8f controls how many digits to print after the decimal point, which is not the same thing.

How to use Fiber?

2015-02-24 Thread FrankLike via Digitalmars-d-learn
There is a int[] ,how to use the Fiber execute it ? Such as : import std.stdio; import core.thread; class DerivedFiber : Fiber { this() { super( run ); } private : void run() { printf( Derived fiber running.\n ); faa(); } } int[] v; void

Re: Deprecation process documented?

2015-02-24 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, February 24, 2015 08:49:55 Jacob Carlborg via Digitalmars-d-learn wrote: Is the deprecation process used for Phobos and druntime code documented somewhere? I.e. how long after a deprecation is a symbols removed and so on. No, it's not documented. I really should put it up on the

Re: Struct inheritance

2015-02-24 Thread amber via Digitalmars-d-learn
On Tuesday, 24 February 2015 at 12:16:43 UTC, Tobias Pankrath wrote: On Tuesday, 24 February 2015 at 12:05:51 UTC, amber wrote: Hi, Is it possible in D to have inheritance using value types, i.e. structs? No runtime polymorphism, but a kind of sub typing via alias this. struct S { void

Re: how to stop a variable from being optimized out

2015-02-24 Thread Rory via Digitalmars-d-learn
On Tuesday, 24 February 2015 at 06:48:26 UTC, ketmar wrote: but why do you need this? just use `atomicLoad` to get shared variable value, it will do the right caching. Nice! Thanks. Tested atomicLoad and it is slightly faster for my non blocking queue.

Re: Struct inheritance

2015-02-24 Thread Tobias Pankrath via Digitalmars-d-learn
On Tuesday, 24 February 2015 at 12:05:51 UTC, amber wrote: Hi, Is it possible in D to have inheritance using value types, i.e. structs? No runtime polymorphism, but a kind of sub typing via alias this. struct S { void foo() { writeln(S.foo); } struct T { S s; alias s this; } T t; t.foo();

Struct inheritance

2015-02-24 Thread amber via Digitalmars-d-learn
Hi, Is it possible in D to have inheritance using value types, i.e. structs? Also I don't quite understand how copy ctors work in D. Do I need to implement opAssign(S other) {}, or this(this) {} and what's the difference between these two? Thanks, Amber

Re: Deprecation process documented?

2015-02-24 Thread FrankLike via Digitalmars-d-learn
On Tuesday, 24 February 2015 at 07:49:55 UTC, Jacob Carlborg wrote: Can you help me about 'Concurrency in D'? Thank you. http://forum.dlang.org/thread/dugsyhsswoovgywpl...@forum.dlang.org Some people think rust is better ,but I think D is better. But I don't know that how to use 'Concurrency

Re: Deprecation process documented?

2015-02-24 Thread Jacob Carlborg via Digitalmars-d-learn
On 2015-02-24 10:20, Jonathan M Davis via Digitalmars-d-learn wrote: No, it's not documented. I really should put it up on the wiki. The current process is that if the replacement for the symbol is being introduced at the same time, the old symbol will be marked as deprecated for a release (so

Re: Deprecation process documented?

2015-02-24 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, February 24, 2015 17:57:12 Jacob Carlborg via Digitalmars-d-learn wrote: On 2015-02-24 10:20, Jonathan M Davis via Digitalmars-d-learn wrote: No, it's not documented. I really should put it up on the wiki. The current process is that if the replacement for the symbol is being

Re: Struct inheritance

2015-02-24 Thread ketmar via Digitalmars-d-learn
On Tue, 24 Feb 2015 12:05:50 +, amber wrote: Hi, Is it possible in D to have inheritance using value types, i.e. structs? Also I don't quite understand how copy ctors work in D. Do I need to implement opAssign(S other) {}, or this(this) {} and what's the difference between these two?

Re: Struct inheritance

2015-02-24 Thread ketmar via Digitalmars-d-learn
On Tue, 24 Feb 2015 18:19:39 +, ketmar wrote: On Tue, 24 Feb 2015 12:05:50 +, amber wrote: Hi, Is it possible in D to have inheritance using value types, i.e. structs? Also I don't quite understand how copy ctors work in D. Do I need to implement opAssign(S other) {}, or

Re: Struct inheritance

2015-02-24 Thread ketmar via Digitalmars-d-learn
On Tue, 24 Feb 2015 12:05:50 +, amber wrote: Hi, Is it possible in D to have inheritance using value types, i.e. structs? Also I don't quite understand how copy ctors work in D. Do I need to implement opAssign(S other) {}, or this(this) {} and what's the difference between these two?

Re: how to stop a variable from being optimized out

2015-02-24 Thread ketmar via Digitalmars-d-learn
On Tue, 24 Feb 2015 12:50:53 +, Rory wrote: On Tuesday, 24 February 2015 at 06:48:26 UTC, ketmar wrote: but why do you need this? just use `atomicLoad` to get shared variable value, it will do the right caching. Nice! Thanks. Tested atomicLoad and it is slightly faster for my non

Re: Deprecation process documented?

2015-02-24 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Feb 24, 2015 at 09:55:28AM -0800, Jonathan M Davis via Digitalmars-d-learn wrote: [...] Regardless, when a symbol is either marked as scheduled for deprecation in the docs or outright deprecated, a date is usually put in the docs for when it will be moved to the next deprecation stage,

Re: Struct inheritance

2015-02-24 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Feb 24, 2015 at 06:22:05PM +, ketmar via Digitalmars-d-learn wrote: On Tue, 24 Feb 2015 12:05:50 +, amber wrote: Hi, Is it possible in D to have inheritance using value types, i.e. structs? Also I don't quite understand how copy ctors work in D. Do I need to

Re: @trusted and return ref

2015-02-24 Thread anonymous via Digitalmars-d-learn
On Tuesday, 24 February 2015 at 22:37:58 UTC, Ola Fosheim Grøstad wrote: 1. My understanding is that @trusted is supposed to give memory safety escapes by providing a context which reestablish a memory safety context on return. Yep, that's how I got it, too. A @trusted function is supposed to

Re: strings and array literal mutability

2015-02-24 Thread Ali Çehreli via Digitalmars-d-learn
On 02/24/2015 02:51 PM, Tobias Pankrath wrote: On Tuesday, 24 February 2015 at 22:12:57 UTC, Freddy wrote: Why are strings immutable but array literals are not? Because string is an alias for immutable(char). You meant immutable(char)[]. :) Ali

Re: @trusted and return ref

2015-02-24 Thread via Digitalmars-d-learn
On Tuesday, 24 February 2015 at 22:49:17 UTC, w0rp wrote: In general, @trusted means I have proven myself that this code is actually safe, eeven though it uses unsafe features. The compiler has to be pessimistic and assume that everything which can be used unsafely will be used unsafely.

Re: @trusted and return ref

2015-02-24 Thread via Digitalmars-d-learn
On Wednesday, 25 February 2015 at 00:12:41 UTC, anonymous wrote: If the whole function was @trusted, the compiler wouldn't catch other safety violations that are not related to malloc/free. You don't need to. In C++ you use a separate @trusted data-structure for capturing ownership, aka

Need help with concurrency

2015-02-24 Thread FrankLike via Digitalmars-d-learn
Hello,everyone,what is a better way with concurrency? http://forum.dlang.org/thread/urqxiaairpnrjggqd...@forum.dlang.org Thank you.

strings and array literal mutability

2015-02-24 Thread Freddy via Digitalmars-d-learn
Why are strings immutable but array literals are not?

@trusted and return ref

2015-02-24 Thread via Digitalmars-d-learn
Since neither Andrei or Walter are able to say something sensible on these issues when asked, I apparently need to learn something about the consistency of C memory safety. I'm happy to listen to anyone who can explain this to me: 1. My understanding is that @trusted is supposed to give

Re: @trusted and return ref

2015-02-24 Thread w0rp via Digitalmars-d-learn
On Tuesday, 24 February 2015 at 22:37:58 UTC, Ola Fosheim Grøstad wrote: If this is careful use of @trusted, then I don't see the point of having @trusted at all. What is the purpose? What is it meant to cover? In order for @trusted to make sense in this code segment (

Re: Deprecation process documented?

2015-02-24 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, February 24, 2015 10:05:21 H. S. Teoh via Digitalmars-d-learn wrote: On Tue, Feb 24, 2015 at 09:55:28AM -0800, Jonathan M Davis via Digitalmars-d-learn wrote: [...] Regardless, when a symbol is either marked as scheduled for deprecation in the docs or outright deprecated, a

Re: strings and array literal mutability

2015-02-24 Thread Tobias Pankrath via Digitalmars-d-learn
On Tuesday, 24 February 2015 at 22:12:57 UTC, Freddy wrote: Why are strings immutable but array literals are not? Because string is an alias for immutable(char).