1

I know that the "\p x" command sets the precision for all calculations, but i'm looking for something a bit different. Given a number given computed with high precision, I want to round it to a lower precision for just one part of my code. The reason for this is taking the absolute value of complex numbers tends to make some roundoff errors that cause problems later on. I want those absolute values to be the same, and not have the miniscule errors they have right now.

In other words, how can i make 1.xxxxxxxxxxxxxx -> 1.xxxxxxx for just a specific number?

hardmath
  • 8,753
  • 2
  • 37
  • 65
Dan S
  • 11
  • 2

1 Answers1

2

The simplest solution is

z * precision(1., 100)

to truncate components of z to a relative accuracy of 100 digits. For printing purposes, you can also use printf("%m.nf", z) with standard meanings.

K.B.
  • 861
  • 5
  • 14