1

How would I convert degrees to radians exactly. Rather than showing 0.785398 I want the program to show pi/4.

I am currently using this script to convert degrees into radians.

cout << angle * M_PI / 180.0 << " radians";

Devansh Sharma
  • 144
  • 3
  • 11
  • `exactly` - invent a computer that can store floating numbers exactly. If you want to show _a string_ `"pi/4"` rather then the actual floating point value, you have to implement a library that will do just that. – KamilCuk Jan 29 '19 at 22:21
  • 1
    @KamilCuk You can implement that without needing fancy architecture. For example a `rational` type that stores a numerator and a denumerator, maybe with a bigint library can pretty much do this. No need to invent a new type of computer. Though some *operations* are necessarily approximations, but you can still store those approximations as exact rational values. Maybe a bit trickier if you want to account for irrational values like pi, but can absolutely done in software. – François Andrieux Jan 29 '19 at 22:22
  • convert `angle / 180.0` to a proper fraction and then stick pi in the numerator. – NathanOliver Jan 29 '19 at 22:25
  • Why the negative votes? – Devansh Sharma Jan 29 '19 at 22:29

1 Answers1

1

You might do

 std::cout << angle / 180.0 << " pi radians";

Which will print

 0.25 pi radians

You might be interested by how-to-convert-floats-to-human-readable-fractions to convert 0.25 into 1/4.

Jarod42
  • 203,559
  • 14
  • 181
  • 302