Re: User imput string int and float[DOUBT]

2017-02-16 Thread Jean Cesar via Digitalmars-d-learn
uto read(S)(ref S s, string message) if (isSomeString!S) { import std.string : strip; writef("%s: ", message); s = readln().strip(); return s; } class person { private: string name, address; int age; float height; public: static person fromConsole() {

Re: User imput string int and float[DOUBT]

2017-02-16 Thread Ali Çehreli via Digitalmars-d-learn
e could have benefited from as well. import std.stdio; import std.traits; auto read(T)(ref T t, string message) if (!isSomeString!T) { writef("%s: ", message); readf(" %s", ); return t; } auto read(S)(ref S s, string message) if (isSomeString!S) { import std.stri

Re: User imput string int and float[DOUBT]

2017-02-16 Thread Jean Cesar via Digitalmars-d-learn
On Thursday, 16 February 2017 at 02:17:49 UTC, Ali Çehreli wrote: On 02/15/2017 05:49 PM, Jean Cesar wrote: > So I'm a beginner in this language and have very little time I started > I'm interested in apprehending concepts of object orientation > polymorphism inheritance, multiple inheritance

Re: User imput string int and float[DOUBT]

2017-02-15 Thread Ali Çehreli via Digitalmars-d-learn
On 02/15/2017 05:49 PM, Jean Cesar wrote: > So I'm a beginner in this language and have very little time I started > I'm interested in apprehending concepts of object orientation > polymorphism inheritance, multiple inheritance as in c ++ D is similar to C++ but also very different. > but I

Re: User imput string int and float[DOUBT]

2017-02-15 Thread Jean Cesar via Digitalmars-d-learn
n s; } class person { private: string name, address; int age; float height; public: void setNome() { read(name, "Enter Your Name"); } void setIty() { read(age, "Enter Your Age"); } void setHeight() { read(height

Re: User imput string int and float[DOUBT]

2017-02-15 Thread Ali Çehreli via Digitalmars-d-learn
;, message); readf(" %s", ); return t; } auto read(S)(ref S s, string message) if (isSomeString!S) { import std.string : strip; writef("%s: ", message); s = readln().strip(); return s; } class person { private: string name, address; int age; f

User imput string int and float[DOUBT]

2017-02-15 Thread Jean Cesar via Digitalmars-d-learn
How do I make a class person where I use set and get methods to imput the user type: Import std.stdio; class person { private: string name, address; int age; float height; public: void setNome() { write("Enter Your Name:"); // the problem is here how am I goi

Re: Int to float?

2015-03-06 Thread bearophile via Digitalmars-d-learn
Ola Fosheim Grøstad: D claims to follow C, so using unions for type punning is ultimately implementation defined. I am not sure if D is the same as C regarding this. Bye, bearophile

Re: Int to float?

2015-03-06 Thread Nicolas Sicard via Digitalmars-d-learn
-portable, since some hardware architectures may use different representations (e.g. different byte order on int and float). Then maybe use std.bitmanip? import std.bitmanip; int i = 5; float f = bigEndianToNative!float(nativeToBigEndian(i)); // or float f = littleEndianToNative!float

Re: Int to float?

2015-03-05 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 5 March 2015 at 20:32:20 UTC, anonymous wrote: That's not really simpler, though. Maybe, but I think the union is a bit nicer because then the compiler is responsible for more of the details. For example, it should work with class objects without the complication of dealing

Re: Int to float?

2015-03-05 Thread anonymous via Digitalmars-d-learn
On Thursday, 5 March 2015 at 20:03:09 UTC, Benjamin Thaut wrote: int someValue = 5; float sameBinary = *(cast(float*)cast(void*)someValue); The cast(void*) isn't necessary.

Re: Int to float?

2015-03-05 Thread Taylor Hillegeist via Digitalmars-d-learn
On Thursday, 5 March 2015 at 20:03:09 UTC, Benjamin Thaut wrote: Am 05.03.2015 um 21:00 schrieb Taylor Hillegeist: How to I cast a Int to float without changing its binary representation? int someValue = 5; float sameBinary = *(cast(float*)cast(void*)someValue); ahh of course! lol :)

Re: Int to float?

2015-03-05 Thread badlink via Digitalmars-d-learn
On Thursday, 5 March 2015 at 20:16:55 UTC, anonymous wrote: On Thursday, 5 March 2015 at 20:03:09 UTC, Benjamin Thaut wrote: int someValue = 5; float sameBinary = *(cast(float*)cast(void*)someValue); The cast(void*) isn't necessary. Actually even the cast is unecessary, just use a uniform

Int to float?

2015-03-05 Thread Taylor Hillegeist via Digitalmars-d-learn
How to I cast a Int to float without changing its binary representation?

Re: Int to float?

2015-03-05 Thread Benjamin Thaut via Digitalmars-d-learn
Am 05.03.2015 um 21:00 schrieb Taylor Hillegeist: How to I cast a Int to float without changing its binary representation? int someValue = 5; float sameBinary = *(cast(float*)cast(void*)someValue);

Re: Int to float?

2015-03-05 Thread anonymous via Digitalmars-d-learn
On Thursday, 5 March 2015 at 20:21:18 UTC, badlink wrote: On Thursday, 5 March 2015 at 20:16:55 UTC, anonymous wrote: On Thursday, 5 March 2015 at 20:03:09 UTC, Benjamin Thaut wrote: int someValue = 5; float sameBinary = *(cast(float*)cast(void*)someValue); The cast(void*) isn't necessary

Re: Int to float?

2015-03-05 Thread Jesse Phillips via Digitalmars-d-learn
On Thursday, 5 March 2015 at 20:06:55 UTC, Taylor Hillegeist wrote: On Thursday, 5 March 2015 at 20:03:09 UTC, Benjamin Thaut wrote: Am 05.03.2015 um 21:00 schrieb Taylor Hillegeist: How to I cast a Int to float without changing its binary representation? int someValue = 5; float sameBinary

Re: Int to float?

2015-03-05 Thread via Digitalmars-d-learn
representations (e.g. different byte order on int and float). D claims to follow C, so using unions for type punning is ultimately implementation defined. In C++ using unions for type punning is illegal/undefined behaviour, so in C++ you should use memcpy. Memcpy also has the advantage of explicitly