473,699 Members | 2,628 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How To Make Your Own Variable Type?

Yeah, I need some help, I'm not a very good programmer but I've tried a
lot of languages, and anyways, I want to start applying programming to
physics, and I would like to learn how to make a Variable Type for a
little program I am making. Basically a 32byte or up sized long double
(which is 16 bytes from what I was told). I just really want to learn
how to be able to declare my own type so that I could do things with
very good accuracy.... Thanks beforehand for those who reply.....

Nov 15 '05 #1
5 3798
frankhall36 wrote:
Yeah, I need some help, I'm not a very good programmer but I've tried a
lot of languages, and anyways, I want to start applying programming to
physics, and I would like to learn how to make a Variable Type for a
little program I am making. Basically a 32byte or up sized long double
(which is 16 bytes from what I was told). I just really want to learn
how to be able to declare my own type so that I could do things with
very good accuracy.... Thanks beforehand for those who reply.....


Custom variables? You can define your types, structures. If you want to
deal with good accuracy and numeric robustness I suggest looking for a
good library... take a look at the Gnu Scientific Library.
Nov 15 '05 #2
>Yeah, I need some help, I'm not a very good programmer but I've tried a
lot of languages, and anyways, I want to start applying programming to
physics, and I would like to learn how to make a Variable Type for a
little program I am making.
The only thing approximating this you can do is declare a type using
existing C types, and typedef it. Typedef doesn't really create
new types, but let you make a new name for one.

Then it's up to you to write all the code that deals with your new
type. Doing high-precision floating point right takes a LOT of
work. The new type might just be an array of unsigned longs (or a
structure containing one) with enough of them to hold the data you
need. Or it might be an array of unsigned chars.
Basically a 32byte or up sized long double
(which is 16 bytes from what I was told). I just really want to learn
A typical "long double" available from a hardware floating point
unit is 80 bits long. That might be padded for alignment purposes,
but you don't get more accuracy out of the pad bits.
how to be able to declare my own type so that I could do things with
very good accuracy.... Thanks beforehand for those who reply.....


Unlike C++, you don't get to overload operators, so code involving
ultralong floating point will likely have to be done with function
calls or macros.

There are existing packages for high-precision math, such as GNU
gmp. GNU gmp includes integer, rational, and floating-point math.

Gordon L. Burditt
Nov 15 '05 #3
I'm doing it in C++ not C, by the way. I had seen other people post
stuff about C++ here too, so I did. How would you go about doing the
whole array thing? Using an array of longs to do that?

Nov 15 '05 #4
frankhall36 wrote:

I'm doing it in C++ not C, by the way. I had seen other people post
stuff about C++ here too, so I did. ... snip ...


Not any knowledgeable people, you didn't. Whatever 'it' may be.
You also didn't see anyone knowledgeable posting without proper
quotations. If you had lurked here a short time to see what was
going on you would have seen many advisories about how to properly
use that fouled up google interface. Learn something before coming
back.

--
Chuck F (cb********@yah oo.com) (cb********@wor ldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net> USE worldnet address!

Nov 15 '05 #5
On Thu, 30 Jun 2005 22:04:26 -0700, frankhall36 wrote:
I'm doing it in C++ not C, by the way. I had seen other people post
stuff about C++ here too, so I did. How would you go about doing the
whole array thing? Using an array of longs to do that?


People posting C++ stuff here are typically directed towards comp.lang.c++
which is an appropriate newsgroup for discussing that language.

Lawrence

Nov 15 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
6235
by: AnnMarie | last post by:
<script language="JavaScript" type="text/javascript"> <!-- function validate(theForm) { var validity = true; // assume valid if(frmComments.name.value=='' && validity == true) { alert('Your full name is required. Please enter your full name!'); validity = false; frmComments.name.focus();
7
1425
by: Daniel | last post by:
how to make two references to one string that stay refered to the same string reguardless of the changing value in the string?
7
1864
by: Ben | last post by:
Hi all, I'm not yet good at thinking the right way in c++ so although I could solve this problem, I'm not sure if they way I'm thinking of is the best way to do it. I need a data type or class or something that can hold either an int, or a float, knows which one it is holding, and will allow me to do comparisons with instances of it without the code which asks for the comparison having to know which one it is. So maybe I could do it...
7
6289
by: Kapt. Boogschutter | last post by:
I'm trying to create a function that has at least 1 Argument but can also contain any number of Arguments (except 0 because my function would have no meaning for 0 argument). The arguments passed to the function are strings or must be (automaticly converted to a string e.g. the number 10 should become the string "10". My problem is that I can only find samples and description of printf() like functions where the optional arguments and...
14
2539
by: sathya_me | last post by:
Dear clc, I have a variable void *a; Since variable "a" can be assigned (point to) any type and also any type can be assigned to "a" (i.e means "a" = any typed variable; any typed variable = "a". Considering the above I have a function, which is declared and defined to take any type of parameter with void* return-type foo (void *a); In the processes of assignment of value to the variable "a" I want to
6
4883
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of the html page controls the form fields that are required. It doesn't function like it's supposed to and I can leave all the fields blank and it still submits the form. Also I can't get it to transfer the file in the upload section. The file name...
19
2433
by: zzw8206262001 | last post by:
Hi,I find a way to make javescript more like c++ or pyhon There is the sample code: function Father(self) //every contructor may have "self" argument { self=self?self:this; //every class may have this statement self.hello = function() {
7
1631
by: John Harrison | last post by:
This is from SGI's FAQ, its the justification for why list<T>::size() is linear time in their library (and in gcc library too since their code is based on SGI) <quote> Why is list<>::size() linear time? The size() member function, for list and slist, takes time proportional to the number of elements in the list. This was a deliberate tradeoff. The only way to get a constant-time size() for linked lists would be to
7
1223
by: aspineux | last post by:
Hi I read the PEP 3117 about the new "Postfix type declarations" in Python3000. THIS PEP as been REJECTED ! But ... The notation in the PEP is very ugly ! This make python code more difficult to read! Anyway when I switched to python (from C, C++, ..), I suffered a lot
0
8685
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8613
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9172
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8908
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 most users, this new feature is actually very convenient. If you want to control the update process,...
1
6532
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5869
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4374
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3054
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
3
2008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.