TfidfVectorizer does not preserve dtype for large size inputs

### Describe the bug

After fitting `TfidfVectorizer`, its `idf_` has `dtype` `np.float64` regardless of the provided `dtype` when the input data are large. The conversion from `np.float32` to `np.float64` happens [here](https://github.com/scikit-learn/scikit-learn/blob/d5082d32de2797f9594c9477f2810c743560a1f1/sklearn/feature_extraction/text.py#L1666).

Not propagating `dtype` to `TfidfTransformer` has been [discussed](https://github.com/scikit-learn/scikit-learn/pull/10443) in the past. Back then passing `dtype` to `np.log` or adding `.astype(dtype)` to `np.log` were not approved.

### Steps/Code to Reproduce

```python
from sklearn.feature_extraction.text import TfidfVectorizer
import pandas as pd
import numpy as np
import uuid

#check for 100 strings with output as np.float32, works fine
small_data=[str(uuid.uuid4()) for i in range(100)]
X = pd.Series(small_data)
vectorizer = TfidfVectorizer(dtype=np.float32)
vectorizer.fit(X)
print(vectorizer.idf_.dtype)

#check for 1000000 strings with output as np.float32
#the output of the following has dtype np.float64
large_data=[str(uuid.uuid4()) for i in range(1000000)]
X = pd.Series(large_data)
vectorizer = TfidfVectorizer(dtype=np.float32)
vectorizer.fit(X)
print(vectorizer.idf_.dtype)
```

### Expected Results

```python
float32
float32
```

### Actual Results

```python
float32
float64
```

### Versions

```shell
System:
    python: 3.10.13 (main, Feb  7 2024, 08:26:19) [Clang 15.0.0 (clang-1500.1.0.2.5)]
executable: .../bin/python
   machine: macOS-14.6.1-arm64-arm-64bit

Python dependencies:
      sklearn: 1.5.2
          pip: 24.2
   setuptools: 65.5.0
        numpy: 1.23.5
        scipy: 1.14.1
       Cython: None
       pandas: 2.2.3
   matplotlib: 3.9.2
       joblib: 1.4.2
threadpoolctl: 3.5.0

Built with OpenMP: True

threadpoolctl info:
       user_api: blas
   internal_api: openblas
    num_threads: 12
         prefix: libopenblas
       filepath: .../lib/python3.10/site-packages/numpy/.dylibs/libopenblas64_.0.dylib
        version: 0.3.20
threading_layer: pthreads
   architecture: armv8

       user_api: openmp
   internal_api: openmp
    num_threads: 12
         prefix: libomp
       filepath: .../lib/python3.10/site-packages/sklearn/.dylibs/libomp.dylib
        version: None
```

COMMENT:
I am getting the expected results, i.e.:
- `float32`
- `float32`

Here are my system dependencies:

```
System:
    python: 3.11.5 (tags/v3.11.5:cce6ba9, Aug 24 2023, 14:38:34) [MSC v.1936 64 bit (AMD64)]
executable: C:\Users\rachi\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\python.exe
   machine: Windows-10-10.0.22631-SP0

Python dependencies:
      sklearn: 1.3.2
          pip: 24.2
   setuptools: 65.5.0
        numpy: 1.26.2
        scipy: 1.11.4
       Cython: None
       pandas: 2.1.3
   matplotlib: 3.9.2
       joblib: 1.3.2
threadpoolctl: 3.2.0

Built with OpenMP: True

threadpoolctl info:
       user_api: openmp
   internal_api: openmp
    num_threads: 4
         prefix: vcomp
       filepath: C:\Users\rachi\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\scipy.libs\libopenblas_v0.3.20-571-g3dec11c6-gcc_10_3_0-c2315440d6b6cef5037bad648efc8c59.dll
        version: 0.3.21.dev
threading_layer: pthreads
   architecture: Haswell
```

Labels: Bug