473,513 Members | 2,688 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is there anythng called 'zeroes' and 'infinity' in C++?

25 New Member
hello,
I am trying to write a few matlab code lines in C++. I want to write these. Pls help!!!!
In matlab it is:
x=zeros(1,10);
y=inf(1,5);
How do i write this in C++????????
thank u in adv,
prads
Oct 21 '07 #1
6 1744
oler1s
671 Recognized Expert Contributor
I don't have to access to Matlab on this computer. Mind explaining what those two Matlab functions do with examples, and why you can't replicate their functionality, so I don't have to do the research myself?
Oct 21 '07 #2
prads
25 New Member
hello,
I am trying to write a few matlab code lines in C++. I want to write these. Pls help!!!!
In matlab it is:
x=zeros(1,10); // a matrix 'x' is created with 1 row and 10 columns all having zeros
y=inf(1,5); // a matrix 'y' is created with 1 row and 5 colmns all having infinity.
How do i write this in C++????????
Is there anythng called ZEROS and INFINITY in C++???????
thank u in adv,
prads
Oct 22 '07 #3
oler1s
671 Recognized Expert Contributor
There are no functions called zeroes and infinity in C++. You have to replicate their equivalent using your knowledge of C++.

This is a double post, as you had already started a thread on this. Furthermore, your excessive use of bad punctuation, combined with poor spelling, suggests that you aren't really interested in figuring out the answer so much as one of us giving you the answer.

If you want some help, you would do well to give us the following information: what is the context of these functions? What program are you creating? If you need Matlab functions, why use C++? If you still need to replicate those functions, what have you thought as a possible solution?
Oct 23 '07 #4
RRick
463 Recognized Expert Contributor
Ignoring the spelling :-) There are a couple of issues you are going to have to figure out.

First, how are you going to convert from the MatLab arrays to C++ arrays. Since you are dealing with one dimensional arrays, use the same in C++.

Second how to initialize the arrays? If the arrays are small, then array initialization is the simplest way to go.
Expand|Select|Wrap|Line Numbers
  1. // Init array with 3 values of 33 each
  2. int array[3] = { 33, 33, 33];
If the arrays are large, then a for loop is best.

Finally, how to set values to zero? That's easy, just do it. Infinity is a little harder. For each data type (i.e. int, long, double, etc) there are corresponding INT_MAX, LONG_MAX, etc. values in the include file limits.h. Use these values in your initialization.
Oct 23 '07 #5
Koolioman
11 New Member
I've done a lot of math programs, and I know that if you divide a number by zero and convert is to a string, it will say infinity.
Oct 25 '07 #6
RRick
463 Recognized Expert Contributor
That might be true for floating point, because floats have special values for nan and inf. I don't know if you can use the float inf value for further calculations ( I doubt it).

It won't be true for integers. For integers, you'll get a floating point exception.
Oct 25 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

108
6298
by: Bryan Olson | last post by:
The Python slice type has one method 'indices', and reportedly: This method takes a single integer argument /length/ and computes information about the extended slice that the slice object would describe if applied to a sequence of length items. It returns a tuple of three integers; respectively these are the /start/ and /stop/ indices and...
2
4331
by: Russell Smith | last post by:
Timestamps support infinity. However if appears dates do not. When timestamps are cast to dates, there is no output. Is this an acceptable option or not? Below are a number of examples showing what I am experiencing. The last own shows how converting timestamps to dates and then ordering doesn't give you the order you want. Maybe you...
5
4171
by: Peter Hansen | last post by:
I'm investigating a puzzling problem involving an attempt to generate a constant containing an (IEEE 754) "infinity" value. (I understand that special float values are a "platform-dependent accident" etc...) The issue appears possibly to point to a bug in the Python compiler, with it producing inconsistent results. I'm using "Python 2.4.2...
2
1893
by: Pierre Rouleau | last post by:
Hi all, When using Python 2.4.x on a Win32 box, marshal.loads(marshal.dumps(1e66666)) returns 1.0 instead of infinity as it should and does under Python 2.5 (also running on Win32 ). This problem was reported in another thread here by Peter Hansen...
12
2547
by: horacius.rex | last post by:
Hi, I have a code that in some part of the program calculates 1/x for a lot of different x's. About 1 of 100 times x is equal to zero, so when I print the result I obtain inf. I wonder if there is a way to detect this "infinity" and convert it to the float zero. I mean something like for i = .... calculate 1/x_i
5
9776
by: westhood | last post by:
In my program I must have some variables which values are infinity. It means the variable must be bigger than any integer. And if we add some to it, its value should still be infinity. I try to use the max value of int ,but it will cause overflow if you add something to it. I also try to write a class INF,in which I overload operator +...
8
46920
by: stainless | last post by:
Is it possible, using the ToString function, to take an integer and conver to a string of fiexd width with the leading spaces padded with zeroes. e.g. integer 123 converted to a string of length 9 with 6 leading zeroes i.e. 000000123 integer 98765432 converted to a string of length 9 with 1 leading zero i.e. 098765432
14
5511
by: Jim Langston | last post by:
The output of the following program is: 1.#INF 1 But: 1.#INF 1.#INF was expected and desired. How can I read a value of infinity from a stream?
13
2298
by: kimiraikkonen | last post by:
Hello, I have an aritmetic calculation like this: First note that: i need a "timer" to get the value for value3. (however removing "timer" didn't differ) Dim value1 As Long Dim value2 As String Dim value3 As String value3 = (value2 * 8) / value1
0
7270
marktang
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...
0
7178
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7397
Oralloy
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. ...
0
7563
jinu1996
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...
1
7125
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7543
tracyyun
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...
1
5102
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4757
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...
0
1612
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.