tretool 0.2.1__py3-none-any.whl → 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
tretool/mathlib.py CHANGED
@@ -585,36 +585,3 @@ def _decimal_gamma(x: Decimal, prec: PrecisionType = None) -> Decimal:
585
585
  return _decimal_sqrt(2 * PI, prec) * t ** (z + Decimal('0.5')) * _decimal_exp(-t, prec) * x
586
586
 
587
587
  return +_gamma(x)
588
-
589
- # ==================== 测试代码 ====================
590
- if __name__ == "__main__":
591
- # 验证基础函数
592
- assert abs(sqrt(2) - 1.414213562) < 1e-6
593
- assert abs(exp(1) - float(E)) < 1e-6
594
- assert abs(ln(float(E))) - 1 < 1e-6
595
-
596
- # 三角函数验证
597
- assert abs(sin(PI/2) - 1) < 1e-10
598
- assert abs(cos(PI) + 1) < 1e-10
599
- assert abs(tan(PI/4) - 1) < 1e-10
600
-
601
- # 反三角函数验证
602
- assert abs(asin(0.5) - 0.523598775) < 1e-6
603
- assert abs(acos(0.5) - 1.047197551) < 1e-6
604
- assert abs(atan(1) - PI/4) < 1e-10
605
-
606
- # 双曲函数验证
607
- assert abs(sinh(0)) < 1e-10
608
- assert abs(cosh(0) - 1) < 1e-10
609
- assert abs(tanh(1) - 0.761594155) < 1e-6
610
-
611
- # 特殊函数验证
612
- assert factorial(5) == 120
613
- assert abs(gamma(0.5) - sqrt(PI)) < 1e-6
614
-
615
- # 高精度测试
616
- MathConfig.set_precision(50)
617
- assert str(exp(Decimal(1)))[:52] == "2.71828182845904523536028747135266249775724709369995"
618
- assert str(ln(Decimal(10)))[:52] == "2.30258509299404568401799145468436420760110148862877"
619
-
620
- print("所有测试通过!")
tretool/path.py CHANGED
@@ -184,6 +184,25 @@ class PurePath(ABC):
184
184
  """
185
185
  return self.__class__(self, *args)
186
186
 
187
+ def to_str(self) -> str:
188
+ """
189
+ 将路径对象转换为字符串形式。
190
+
191
+ 返回:
192
+ str: 使用系统路径分隔符的路径字符串表示,效果等同于直接调用 str(path_obj)。
193
+
194
+ 注意:
195
+ - 转换结果取决于操作系统的路径规范(Windows/Linux 可能不同)
196
+ - 对于纯路径对象(PurePath),不会验证路径是否真实存在
197
+
198
+ 示例:
199
+ ```
200
+ >>> p = Path('/usr/local/bin')
201
+ >>> p.to_str()
202
+ '/usr/local/bin'
203
+ """
204
+ return str(self)
205
+
187
206
  def __truediv__(self, other) -> 'PurePath':
188
207
  """
189
208
  使用/运算符连接路径