Skip to content
This repository was archived by the owner on Feb 27, 2026. It is now read-only.

Commit a2a11fb

Browse files
Merge branch 'main' into edit-csharp-arrays
2 parents d99f773 + de20349 commit a2a11fb

13 files changed

Lines changed: 916 additions & 1 deletion

File tree

bin/concept-of-the-week.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
content/git/concepts/checkout/checkout.md
1+
content/swift/concepts/ranges/ranges.md
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
---
2+
Title: 'Log10()'
3+
Description: 'Returns the base-10 logarithm of a specified number.'
4+
Subjects:
5+
- 'Computer Science'
6+
- 'Web Development'
7+
Tags:
8+
- 'Arithmetic'
9+
- 'Functions'
10+
- 'Math'
11+
- 'Methods'
12+
CatalogContent:
13+
- 'learn-c-sharp'
14+
- 'paths/computer-science'
15+
---
16+
17+
In C#, the **`Math.Log10()`** [method](https://www.codecademy.com/resources/docs/c-sharp/methods) calculates the base-10 logarithm of a given number. This logarithm represents the power to which 10 must be raised to obtain the input value. The method is defined in the `System` namespace.
18+
19+
## Syntax
20+
21+
```pseudo
22+
Math.Log10(number);
23+
```
24+
25+
**Parameters:**
26+
27+
- `number`: A `double` value whose base-10 logarithm is computed.
28+
29+
**Return value:**
30+
31+
Returns a `double` that represents the base-10 logarithm of `number`.
32+
33+
Return values for different inputs:
34+
35+
- If the input is a positive number, the method returns its base-10 logarithm.
36+
- If the input is `0`, the method returns `NegativeInfinity`.
37+
- If the input is a negative number, the method returns `NaN`.
38+
- If the input is `NaN`, the method returns `NaN`.
39+
- If the input is `PositiveInfinity`, the method returns `PositiveInfinity`.
40+
- If the input is `NegativeInfinity`, the method returns `NaN`.
41+
42+
## Example
43+
44+
The example below demonstrates the return values of `Math.Log10()` for different inputs:
45+
46+
```cs
47+
using System;
48+
49+
class Geeks {
50+
public static void Main(String[] args) {
51+
double a = 4.55;
52+
double b = 0;
53+
double c = -2.45;
54+
double nan = Double.NaN;
55+
double positiveInfinity = Double.PositiveInfinity;
56+
double negativeInfinity = Double.NegativeInfinity;
57+
58+
Console.WriteLine(Math.Log10(a));
59+
Console.WriteLine(Math.Log10(b));
60+
Console.WriteLine(Math.Log10(c));
61+
Console.WriteLine(Math.Log10(nan));
62+
Console.WriteLine(Math.Log10(positiveInfinity));
63+
Console.WriteLine(Math.Log10(negativeInfinity));
64+
}
65+
}
66+
```
67+
68+
The output of the code is:
69+
70+
```shell
71+
0.658011396657112
72+
-Infinity
73+
NaN
74+
NaN
75+
Infinity
76+
NaN
77+
```
78+
79+
## Codebyte Example
80+
81+
This codebyte example calculates the base-10 logarithm of a given number and prints the result:
82+
83+
```codebyte/csharp
84+
using System;
85+
86+
class Program {
87+
static void Main() {
88+
double x = 10.0;
89+
double result = Math.Log10(x);
90+
91+
Console.WriteLine($"The base-10 logarithm of {x} is {result}");
92+
}
93+
}
94+
```
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
---
2+
Title: 'fpclassify()'
3+
Description: 'Classifies a floating-point value into categories such as zero, normal, subnormal, infinite, or NaN.'
4+
Subjects:
5+
- 'Computer Science'
6+
- 'Data Science'
7+
Tags:
8+
- 'Classification'
9+
- 'Functions'
10+
- 'Math'
11+
CatalogContent:
12+
- 'learn-c-plus-plus'
13+
- 'paths/computer-science'
14+
---
15+
16+
The **`fpclassify()`** [function](https://www.codecademy.com/resources/docs/cpp/functions) in C++ returns an integer value indicating the classification of a floating-point number. It categorizes values as normal, subnormal, zero, infinite, or NaN (Not-a-Number). The function is available through the `<cmath>` header.
17+
18+
## Syntax
19+
20+
```pseudo
21+
fpclassify(x)
22+
```
23+
24+
**Parameters:**
25+
26+
- `x`: A floating-point value (can be `float`, `double`, or `long double`).
27+
28+
**Return value:**
29+
30+
The `fpclassify()` function returns one of the following integer constants:
31+
32+
- `FP_INFINITE`: The value is positive or negative infinity.
33+
- `FP_NAN`: The value is NaN (Not-a-Number).
34+
- `FP_ZERO`: The value is zero.
35+
- `FP_SUBNORMAL`: The value is a subnormal (denormalized) number.
36+
- `FP_NORMAL`: The value is a normal finite non-zero number.
37+
38+
## Example
39+
40+
The following example demonstrates various classifications using `fpclassify()`:
41+
42+
```cpp
43+
#include <iostream>
44+
#include <cmath>
45+
46+
using namespace std;
47+
48+
int main() {
49+
double normal = 1.5;
50+
double zero = 0.0;
51+
double inf = INFINITY;
52+
double nan = NAN;
53+
54+
cout << "Classification of " << normal << ": ";
55+
if (fpclassify(normal) == FP_NORMAL) {
56+
cout << "Normal" << endl;
57+
}
58+
59+
cout << "Classification of " << zero << ": ";
60+
if (fpclassify(zero) == FP_ZERO) {
61+
cout << "Zero" << endl;
62+
}
63+
64+
cout << "Classification of inf: ";
65+
if (fpclassify(inf) == FP_INFINITE) {
66+
cout << "Infinite" << endl;
67+
}
68+
69+
cout << "Classification of nan: ";
70+
if (fpclassify(nan) == FP_NAN) {
71+
cout << "NaN" << endl;
72+
}
73+
74+
return 0;
75+
}
76+
```
77+
78+
The output of this code is:
79+
80+
```shell
81+
Classification of 1.5: Normal
82+
Classification of 0: Zero
83+
Classification of inf: Infinite
84+
Classification of nan: NaN
85+
```
86+
87+
## Codebyte Example
88+
89+
The following runnable example shows how to use `fpclassify()` with different values:
90+
91+
```codebyte/cpp
92+
#include <iostream>
93+
#include <cmath>
94+
95+
using namespace std;
96+
97+
int main() {
98+
double values[] = {1.0, 0.0, INFINITY, NAN, -5.5};
99+
100+
for (double val : values) {
101+
cout << "fpclassify(" << val << ") = ";
102+
103+
switch(fpclassify(val)) {
104+
case FP_INFINITE:
105+
cout << "Infinite";
106+
break;
107+
case FP_NAN:
108+
cout << "NaN";
109+
break;
110+
case FP_ZERO:
111+
cout << "Zero";
112+
break;
113+
case FP_SUBNORMAL:
114+
cout << "Subnormal";
115+
break;
116+
case FP_NORMAL:
117+
cout << "Normal";
118+
break;
119+
}
120+
cout << endl;
121+
}
122+
123+
return 0;
124+
}
125+
```
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
---
2+
Title: 'count()'
3+
Description: 'Returns the number of elements with a specific key in an unordered_set.'
4+
Subjects:
5+
- 'Code Foundations'
6+
- 'Computer Science'
7+
Tags:
8+
- 'Methods'
9+
- 'Sets'
10+
- 'STL'
11+
CatalogContent:
12+
- 'learn-c-plus-plus'
13+
- 'paths/computer-science'
14+
---
15+
16+
The **`count()`** [method](https://www.codecademy.com/resources/docs/cpp/methods) in C++ checks whether a given key exists in a `std::unordered_set`. Since this container stores only unique elements, `count()` will always return one of these two values:
17+
18+
- `1`: If the element is found in the set.
19+
- `0`: If the element is not found in the set.
20+
21+
This method is commonly used as a fast, _O(1)_ average time complexity way to check for element existence.
22+
23+
## Syntax
24+
25+
```pseudo
26+
unordered_set_name.count(key);
27+
```
28+
29+
**Parameters:**
30+
31+
- `key` (const Key&): The value of the element to search for. Must be of the same type as the elements stored in the `unordered_set`.
32+
33+
**Return value:**
34+
35+
Returns an integer. `1` if the element exists, `0` otherwise.
36+
37+
## Example
38+
39+
This example demonstrates using `count()` to check for the presence of elements within a set of [strings](https://www.codecademy.com/resources/docs/cpp/strings):
40+
41+
```cpp
42+
#include <iostream>
43+
#include <string>
44+
#include <unordered_set>
45+
46+
int main() {
47+
std::unordered_set<std::string> inventory = {
48+
"Sword",
49+
"Shield",
50+
"Potion"
51+
};
52+
53+
std::cout << "Inventory contains:\n";
54+
for (const auto& item : inventory) {
55+
std::cout << "- " << item << "\n";
56+
}
57+
58+
// Check for an existing element
59+
if (inventory.count("Sword")) {
60+
std::cout << "\n'Sword' is present (Count: " << inventory.count("Sword") << ").\n";
61+
}
62+
63+
// Check for a missing element
64+
if (inventory.count("Axe") == 0) {
65+
std::cout << "'Axe' is not present (Count: " << inventory.count("Axe") << ").\n";
66+
}
67+
68+
return 0;
69+
}
70+
```
71+
72+
The output of the code is:
73+
74+
```shell
75+
Inventory contains:
76+
- Potion
77+
- Shield
78+
- Sword
79+
80+
'Sword' is present (Count: 1).
81+
'Axe' is not present (Count: 0).
82+
```
83+
84+
## Codebyte Example
85+
86+
Run the codebyte below to check for the presence of an item in a set of integers:
87+
88+
```codebyte/cpp
89+
#include <iostream>
90+
#include <unordered_set>
91+
92+
int main() {
93+
std::unordered_set<int> unique_ids = {101, 205, 330};
94+
95+
int search_key = 205;
96+
int missing_key = 400;
97+
98+
// Check the count for the element 205
99+
std::cout << "Count for " << search_key << ": "
100+
<< unique_ids.count(search_key) << "\n";
101+
102+
// Check the count for the element 400
103+
std::cout << "Count for " << missing_key << ": "
104+
<< unique_ids.count(missing_key) << "\n";
105+
106+
return 0;
107+
}
108+
```

0 commit comments

Comments
 (0)