How To Make Your Own Variable Type?

F

frankhall36

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.....
 
S

Sensei

frankhall36 said:
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.
 
G

Gordon Burditt

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
 
F

frankhall36

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?
 
C

CBFalconer

frankhall36 said:
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.
 
L

Lawrence Kirby

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,165
Latest member
JavierBrak
Top