How can I cast from (long double*) to (const double*)
I have tried:
const double* Value1 = (const double*)Value2;
The compiler does not complain but the actual results when I access
the const double* are incorrect.
Note that the (long double*) is a pointer to an array of long doubles. 16 3812
"ferran" <fe*****@yahoo. com> wrote in message
news:53******** *************** ***@posting.goo gle.com... How can I cast from (long double*) to (const double*)
I have tried: const double* Value1 = (const double*)Value2;
Well you've answered your own question.
The compiler does not complain but the actual results when I access the const double* are incorrect.
Not surprisingly.
Note that the (long double*) is a pointer to an array of long doubles.
I think the question you meant to ask is how to I *convert* an array of long
doubles to an array of doubles, casting is not helpful as you have already
found out.
The only way to allocate a new array of doubles and copy the long doubles
over to the new array one by one. Something like
double *Value1 = new double[N];
for (int i = 0; i < N; ++i)
Value1[i] = Value2[i];
john
"ferran" <fe*****@yahoo. com> wrote in message
news:53******** *************** ***@posting.goo gle.com... How can I cast from (long double*) to (const double*)
I have tried: const double* Value1 = (const double*)Value2;
Well you've answered your own question.
The compiler does not complain but the actual results when I access the const double* are incorrect.
Not surprisingly.
Note that the (long double*) is a pointer to an array of long doubles.
I think the question you meant to ask is how to I *convert* an array of long
doubles to an array of doubles, casting is not helpful as you have already
found out.
The only way to allocate a new array of doubles and copy the long doubles
over to the new array one by one. Something like
double *Value1 = new double[N];
for (int i = 0; i < N; ++i)
Value1[i] = Value2[i];
john
On Sat, 10 Apr 2004 16:44:44 +0100 in comp.lang.c++, "John Harrison"
<jo************ *@hotmail.com> wrote, The only way to allocate a new array of doubles and copy the long doubles over to the new array one by one. Something like
double *Value1 = new double[N]; for (int i = 0; i < N; ++i) Value1[i] = Value2[i];
Surely there is something better than copying one by one.
std::vector<dou ble> Value1( Value2, Value2+N );
Or at the worst
std::copy(Value 2, Value2+N, Value1);
Why would you ever write a 'for' loop for that? I don't get it.
On Sat, 10 Apr 2004 16:44:44 +0100 in comp.lang.c++, "John Harrison"
<jo************ *@hotmail.com> wrote, The only way to allocate a new array of doubles and copy the long doubles over to the new array one by one. Something like
double *Value1 = new double[N]; for (int i = 0; i < N; ++i) Value1[i] = Value2[i];
Surely there is something better than copying one by one.
std::vector<dou ble> Value1( Value2, Value2+N );
Or at the worst
std::copy(Value 2, Value2+N, Value1);
Why would you ever write a 'for' loop for that? I don't get it.
ferran wrote: How can I cast from (long double*) to (const double*)
I have tried: const double* Value1 = (const double*)Value2;
The compiler does not complain but the actual results when I access the const double* are incorrect.
The above cast is only appropriate if you have a long double* that
actually doesn't point to a long double, but to a double.
Note that the (long double*) is a pointer to an array of long doubles.
I guess you actually want to have an array of double. In this case you
have to create a copy of your array.
ferran wrote: How can I cast from (long double*) to (const double*)
I have tried: const double* Value1 = (const double*)Value2;
The compiler does not complain but the actual results when I access the const double* are incorrect.
The above cast is only appropriate if you have a long double* that
actually doesn't point to a long double, but to a double.
Note that the (long double*) is a pointer to an array of long doubles.
I guess you actually want to have an array of double. In this case you
have to create a copy of your array.
"David Harmon" <so****@netcom. com> wrote in message
news:40******** *******@news.we st.earthlink.ne t... On Sat, 10 Apr 2004 16:44:44 +0100 in comp.lang.c++, "John Harrison" <jo************ *@hotmail.com> wrote,The only way to allocate a new array of doubles and copy the long doubles over to the new array one by one. Something like
double *Value1 = new double[N]; for (int i = 0; i < N; ++i) Value1[i] = Value2[i];
Surely there is something better than copying one by one. std::vector<dou ble> Value1( Value2, Value2+N );
Or at the worst std::copy(Value 2, Value2+N, Value1);
Why would you ever write a 'for' loop for that? I don't get it.
Granted, but I was just trying to emphasise to the OP that there has to be
some work done to perform the conversion (he was trying to cast), whether
that's done with an explicit loop, or in the internals of std::vector
constructor or std::copy.
john
"David Harmon" <so****@netcom. com> wrote in message
news:40******** *******@news.we st.earthlink.ne t... On Sat, 10 Apr 2004 16:44:44 +0100 in comp.lang.c++, "John Harrison" <jo************ *@hotmail.com> wrote,The only way to allocate a new array of doubles and copy the long doubles over to the new array one by one. Something like
double *Value1 = new double[N]; for (int i = 0; i < N; ++i) Value1[i] = Value2[i];
Surely there is something better than copying one by one. std::vector<dou ble> Value1( Value2, Value2+N );
Or at the worst std::copy(Value 2, Value2+N, Value1);
Why would you ever write a 'for' loop for that? I don't get it.
Granted, but I was just trying to emphasise to the OP that there has to be
some work done to perform the conversion (he was trying to cast), whether
that's done with an explicit loop, or in the internals of std::vector
constructor or std::copy.
john
On Sat, 10 Apr 2004 18:24:06 +0100 in comp.lang.c++, "John Harrison"
<jo************ *@hotmail.com> wrote, Granted, but I was just trying to emphasise to the OP that there has to be some work done to perform the conversion (he was trying to cast), whether that's done with an explicit loop, or in the internals of std::vector constructor or std::copy.
Good point; certainly the ultimate conversion from long double to double
must be done one at a time somewhere. Perhaps it could be done without
needing to store the whole set of results. We don't know how the
results are to be used, but perhaps some kind of adapter class might
avoid a copying step. I guess if the destination is hard coded to
require an array of double there is not much choice but to build one. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Suzanne Vogel |
last post by:
I'd like to convert a double to a binary representation. I can use the
"&" bit operation with a bit mask to convert *non* float types to binary
representations, but I can't use "&" on doubles.
To get around this limitation on double, I'd like to keep the bits of
the double the *same* but change its interpretation to long. I can use
"&" on...
|
by: ferran |
last post by:
How can I cast from (long double*) to (const double*)
I have tried:
const double* Value1 = (const double*)Value2;
The compiler does not complain but the actual results when I access
the const double* are incorrect.
Note that the (long double*) is a pointer to an array of long doubles.
|
by: Gernot Frisch |
last post by:
Hi,
I have a problem. I want to be able to write this:
a = b + d + c;
Where a can be a double or class A;
b,d,c can each indiviually be one of these: double, class A or class
B. The result of an addition is always class A, or double (double +
double can't be changed).
|
by: E. Robert Tisdale |
last post by:
The following example shows how an Object Oriented C programmer
might implement run-time polymorphism.
The Circle "class" is "derived" from the Shape "class".
Pointers to functions
which actually draw and compute the area of a shape
are stored in a "virtual function table"
and a pointer to the appropriate virtual function table
is stored in...
|
by: Nicolas Blais |
last post by:
Hi,
I have this following class which I use as a timer:
#include <sys/time.h>
using namespace std;
class chrono {
public:
chrono() {};
| |
by: Martin Jørgensen |
last post by:
Hi,
Short question:
Any particular reason for why I'm getting a warning here:
(cast from function call of type int to non-matching type double)
xdouble = (double)rand()/(double)RAND_MAX;
|
by: lcw1964 |
last post by:
Greetings again,
I will burden the group with yet another tenderfoot question, but since
conscientious googling hasn't yield a lucid answer I thought I would
risk the shortcut of asking here since I am so very keen to learn to
code in standard C.
Could someone tell me the long double equivalent of atof()? I was
getting some peculiar...
|
by: Grizlyk |
last post by:
1. Can abybody explain me why C++ function can not be overloaded by its
return type? Return type can has priority higher than casting rules.
For example:
char input(); //can be compiled to name "input$char$void"
int input(); //can be compiled to name "input$int$void"
....
int i= 3+'0'+input(); //can be compiled to:...
|
by: Charles Coldwell |
last post by:
James Kanze <james.kanze@gmail.comwrites:
True, with some additional considerations. The commonly used IEEE 754
floating point formats are
single precision: 32 bits including 1 sign bit, 23 significand bits
(with an implicit leading 1, for 24 total), and 8 exponent bits
double precision: 64 bits including 1 sign bit, 52 significand...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |