Register and join over 40,000 other developers!
Recent Topics
-
The Game You Are Waiting For?
WendellHarper - Dec 06 2020 01:21 PM
-
Quora and Reddit Backlinks
WendellHarper - Dec 06 2020 01:14 PM
-
Delete account
pindo - Jul 23 2020 01:33 AM
-
Print specific values from dictionary with a specific key name
Siten0308 - Jun 20 2019 01:43 PM
-
Learn algorithms and programming concepts
johnnylo - Apr 23 2019 07:49 AM
Recent Blog Entries
Recent Status Updates
Popular Tags
- networking
- Managed C++
- stream
- console
- database
- authentication
- Visual Basic 4 / 5 / 6
- session
- Connection
- asp.net
- import
- syntax
- hardware
- html5
- array
- mysql
- java
- php
- c++
- string
- C#
- html
- loop
- timer
- jquery
- ajax
- javascript
- programming
- android
- css
- assembly
- c
- form
- vb.net
- xml
- linked list
- login
- encryption
- pseudocode
- calculator
- sql
- python
- setup
- help
- game
- combobox
- binary
- hello world
- grid
- innerHTML

6 replies to this topic
#1
Posted 26 April 2011 - 11:16 PM
I'm trying to write a simple math program which computes the value of a trigonometric function. Basically just input one value and get another out, but I have two problems:
1. even with cmath included, the constant pi is not provided(I tried PI)
2. I can't seem to input values in the form of division ie 1/2, pi/3. I declared the input variable type double so does that mean you can't enter fractions during cin?
btw, I'm using Dev C++ V4.9.9.2
Thanks in advance
1. even with cmath included, the constant pi is not provided(I tried PI)
2. I can't seem to input values in the form of division ie 1/2, pi/3. I declared the input variable type double so does that mean you can't enter fractions during cin?
btw, I'm using Dev C++ V4.9.9.2
Thanks in advance
#2
Posted 27 April 2011 - 11:34 AM
Sure you can use fractions when declared as double using cin. But fractions can be input as for e.g. 3.232. cin has no way of understanding if you put 3/2 or the like as input. There is no such basic type which is capable of taking rational numbers and computing the floating point result.
There is no such macro as pi or PI in c. you can use a float variable and assign 22/7 to it.
I will emphasize, writing
is okay and legal.
but using cin with a float variable and passing 22/7 on command line expecting it would save it's fractional value is not
There is no such macro as pi or PI in c. you can use a float variable and assign 22/7 to it.
I will emphasize, writing
double b = 22/7;
is okay and legal.
but using cin with a float variable and passing 22/7 on command line expecting it would save it's fractional value is not
#3
Posted 27 April 2011 - 12:37 PM
Sure you can use fractions when declared as double using cin. But fractions can be input as for e.g. 3.232. cin has no way of understanding if you put 3/2 or the like as input. There is no such basic type which is capable of taking rational numbers and computing the floating point result.
There is no such macro as pi or PI in c. you can use a float variable and assign 22/7 to it.
I will emphasize, writingdouble b = 22/7;
is okay and legal.
but using cin with a float variable and passing 22/7 on command line expecting it would save it's fractional value is not
I believe pi exists in cmath, I've used it before. You could always add it in if you wish
#4
Posted 27 April 2011 - 12:54 PM
I believe pi exists in cmath, I've used it before. You could always add it in if you wish
Which compiler were you using? GCC?
PI exists in GCC and some other variants but is not portable and not part of standard c/c++.
cmath (math.h) - C++ Reference
math.h - Wikipedia, the free encyclopedia
lists it under non standard and uses M_PI as macro.
So i believe it probably is not available with dev shed though it can be looked into math.h to be sure or try other options such as M_PI.
#5
Posted 27 April 2011 - 01:01 PM
May be defining this could help _USE_MATH_DEFINES before including math.h as suggested at this stack over flow thread
trigonometry - How to use the PI constant in C++ - Stack Overflow
trigonometry - How to use the PI constant in C++ - Stack Overflow
#6
Posted 27 April 2011 - 02:38 PM
Which compiler were you using? GCC?
PI exists in GCC and some other variants but is not portable and not part of standard c/c++.
cmath (math.h) - C++ Reference
math.h - Wikipedia, the free encyclopedia
lists it under non standard and uses M_PI as macro.
So i believe it probably is not available with dev shed though it can be looked into math.h to be sure or try other options such as M_PI.
MinGW, so yes, GCC. I don't see why you would use anything else though. (Unless it's 16 bit or you need inline ASM)
#7
Posted 27 April 2011 - 11:49 PM
There are a lot of tool chains and compilers which implement their proprietary extensions even in the 32 bit world.
The original thread was about devshed c++ compiler which does not have pi straight out of math.h at least
On windows, Microsoft Visual studio does not have pi defined either.
Borland for sure has a 32bit windows compiler which has a lot of non standard aspects such as it's UI.
I believe none of above is 16 bit or assembly only.
Moreover, there is only desktop world. If we go a little beyond into embedded, there are far more tool chains considering the variety of platforms.
ARM, MIPS, PowerPC, Xilinx are just families of architectures. Even each of them has many different tool chains.
In all of above we can be sure if we use something which is part of standard (ANSI) C or (ISO) C++ , it would be there as it is. But for non standard apis or macros, it may or may not be true. That is why when ever the term 'portable code' is used it is restricted to standard language specification only.
Hope that helps.
The original thread was about devshed c++ compiler which does not have pi straight out of math.h at least
On windows, Microsoft Visual studio does not have pi defined either.
Borland for sure has a 32bit windows compiler which has a lot of non standard aspects such as it's UI.
I believe none of above is 16 bit or assembly only.
Moreover, there is only desktop world. If we go a little beyond into embedded, there are far more tool chains considering the variety of platforms.
ARM, MIPS, PowerPC, Xilinx are just families of architectures. Even each of them has many different tool chains.
In all of above we can be sure if we use something which is part of standard (ANSI) C or (ISO) C++ , it would be there as it is. But for non standard apis or macros, it may or may not be true. That is why when ever the term 'portable code' is used it is restricted to standard language specification only.
Hope that helps.
Also tagged with one or more of these keywords: variable type
Tutorial Forums →
PHP Tutorials →
PHP OOP Tutorial from beginner to advance - (Scope and Calculator - Part 3)Started by papabear, 28 Sep 2012 ![]() |
|
![]() |
||
Language Forums →
C and C++ →
Difference between types and referencesStarted by DreamFM, 22 Jul 2012 ![]() |
|
![]() |
||
Language Forums →
Java →
How to save MySQL query result?Started by alex1, 05 Mar 2012 ![]() |
|
![]() |
||
Language Forums →
PHP →
Prepared statement problemStarted by Rohan21, 02 Jan 2012 ![]() |
|
![]() |
||
Language Forums →
C and C++ →
Help with IPv4 pleaseStarted by toto_7, 17 Nov 2011 ![]() |
|
![]() |
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download