KiCad PCB EDA Suite
Loading...
Searching...
No Matches
eseries.cpp
Go to the documentation of this file.
1/*
2 * This program source code file
3 * is part of KiCad, a free EDA CAD application.
4 *
5 * Copyright (C) 2023 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#include <cmath>
22#include "eseries.h"
23
24namespace ESERIES
25{
26
27const std::vector<uint16_t> ESERIES_VALUES::s_e24table = {
28 100, 110, 120, 130, 150, 160, 180, 200, 220, 240, 270, 300,
29 330, 360, 390, 430, 470, 510, 560, 620, 680, 750, 820, 910
30};
31
32const std::vector<uint16_t> ESERIES_VALUES::s_e192table = {
33 100, 101, 102, 104, 105, 106, 107, 109, 110, 111, 113, 114, 115, 117, 118, 120, 121, 123,
34 124, 126, 127, 129, 130, 132, 133, 135, 137, 138, 140, 142, 143, 145, 147, 149, 150, 152,
35 154, 156, 158, 160, 162, 164, 165, 167, 169, 172, 174, 176, 178, 180, 182, 184, 187, 189,
36 191, 193, 196, 198, 200, 203, 205, 208, 210, 213, 215, 218, 221, 223, 226, 229, 232, 234,
37 237, 240, 243, 246, 249, 252, 255, 258, 261, 264, 267, 271, 274, 277, 280, 284, 287, 291,
38 294, 298, 301, 305, 309, 312, 316, 320, 324, 328, 332, 336, 340, 344, 348, 352, 357, 361,
39 365, 370, 374, 379, 383, 388, 392, 397, 402, 407, 412, 417, 422, 427, 432, 437, 442, 448,
40 453, 459, 464, 470, 475, 481, 487, 493, 499, 505, 511, 517, 523, 530, 536, 542, 549, 556,
41 562, 569, 576, 583, 590, 597, 604, 612, 619, 626, 634, 642, 649, 657, 665, 673, 681, 690,
42 698, 706, 715, 723, 732, 741, 750, 759, 768, 777, 787, 796, 806, 816, 825, 835, 845, 856,
43 866, 876, 887, 898, 909, 920, 931, 942, 953, 965, 976, 988
44};
45
46
48{
49 const std::vector<uint16_t>* baseSeries = &s_e24table;
50 unsigned int baseSeriesSkipValue = 24;
51
52 if( ESERIES::E1 == aESeries || ESERIES::E3 == aESeries || ESERIES::E6 == aESeries
53 || ESERIES::E12 == aESeries || ESERIES::E24 == aESeries )
54 {
55 // The below table depends on the values and order of entries
56 // in the E1,E3, etc. enum in eseries.h
57 const unsigned int skipTableE124[] = { 24, 8, 4, 2, 1 };
58
59 baseSeries = &ESERIES_VALUES::s_e24table;
60 baseSeriesSkipValue = skipTableE124[aESeries];
61 }
62 else if( ESERIES::E48 == aESeries || ESERIES::E96 == aESeries || ESERIES::E192 == aESeries )
63 {
64 baseSeries = &ESERIES_VALUES::s_e192table;
65
66 // The below calculation depends on the values and order of entries
67 // in the E1,E3, etc. enum in eseries.h
68 baseSeriesSkipValue = 1 << ( ESERIES::E192 - aESeries );
69 }
70
71 unsigned int decadeBaseLen = baseSeries->size();
72
73 reserve( decadeBaseLen / baseSeriesSkipValue );
74
75 for( unsigned int idx = 0; idx < decadeBaseLen; idx += baseSeriesSkipValue )
76 {
77 emplace_back( ( *baseSeries )[idx] );
78 }
79
80 shrink_to_fit();
81}
82
83
84ESERIES_IN_DECADE::ESERIES_IN_DECADE( int aESeries, int aDecadeExponent )
85{
86 ESERIES::ESERIES_VALUES seriesValues( aESeries );
87
88 uint16_t decadeBase = seriesValues[0];
89 unsigned int decadeBaseLen = seriesValues.size();
90 double decadeMultiplier = std::pow( 10, aDecadeExponent );
91
92 reserve( decadeBaseLen );
93
94 for( const uint16_t seriesValue : seriesValues )
95 {
96 emplace_back( decadeMultiplier * seriesValue / decadeBase );
97 }
98
99 shrink_to_fit();
100}
101
102} // namespace ESERIES
ESERIES_IN_DECADE(int eSeries, int decadeExponent)
Definition: eseries.cpp:84
static const std::vector< uint16_t > s_e192table
Definition: eseries.h:90
static const std::vector< uint16_t > s_e24table
Definition: eseries.h:89
ESERIES_VALUES(int aESeries)
Definition: eseries.cpp:47
E-Values derived from a geometric sequence formula by Charles Renard were already accepted and widely...
Definition: eseries.cpp:25
@ E3
Definition: eseries.h:71
@ E24
Definition: eseries.h:74
@ E192
Definition: eseries.h:77
@ E12
Definition: eseries.h:73
@ E6
Definition: eseries.h:72
@ E96
Definition: eseries.h:76
@ E1
Definition: eseries.h:70
@ E48
Definition: eseries.h:75