473,320 Members | 1,883 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 3773
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********@yahoo.com) (cb********@worldnet.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
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...
7
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
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...
7
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...
14
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 =...
6
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...
19
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; ...
7
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()...
7
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...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.