Mercurial > hg > octave-lyh
comparison src/graphics.cc @ 12508:919cadf334f8
Simplify calculation of number of tick labels. Bug #32692.
author | Marco Caliari <marco.caliari@univr.it> |
---|---|
date | Tue, 15 Mar 2011 22:45:31 -0700 |
parents | 0dda50ae4997 |
children | 570193964185 |
comparison
equal
deleted
inserted
replaced
12507:41d183070c04 | 12508:919cadf334f8 |
---|---|
4974 min_pos = val; | 4974 min_pos = val; |
4975 } | 4975 } |
4976 } | 4976 } |
4977 } | 4977 } |
4978 | 4978 |
4979 // magform(x) Returns (a, b), where x = a * 10^b, a >= 1., and b is | 4979 // magform(x) Returns (a, b), where x = a * 10^b, abs (a) >= 1., and b is |
4980 // integral. | 4980 // integer. |
4981 | 4981 |
4982 static void | 4982 static void |
4983 magform (double x, double& a, int& b) | 4983 magform (double x, double& a, int& b) |
4984 { | 4984 { |
4985 if (x == 0) | 4985 if (x == 0) |
4987 a = 0; | 4987 a = 0; |
4988 b = 0; | 4988 b = 0; |
4989 } | 4989 } |
4990 else | 4990 else |
4991 { | 4991 { |
4992 double l = std::log10 (std::abs (x)); | 4992 b = static_cast<int> (gnulib::floor (std::log10 (std::abs (x)))); |
4993 double r = std::fmod (l, 1.); | 4993 a = x / std::pow (10.0, b); |
4994 a = std::pow (10.0, r); | |
4995 b = static_cast<int> (l-r); | |
4996 if (a < 1) | |
4997 { | |
4998 a *= 10; | |
4999 b -= 1; | |
5000 } | |
5001 | |
5002 if (x < 0) | |
5003 a = -a; | |
5004 } | 4994 } |
5005 } | 4995 } |
5006 | 4996 |
5007 // A translation from Tom Holoryd's python code at | 4997 // A translation from Tom Holoryd's python code at |
5008 // http://kurage.nimh.nih.gov/tomh/tics.py | 4998 // http://kurage.nimh.nih.gov/tomh/tics.py |