如何在Objective-C中将大数相乘? [英] How do I multiply big numbers together in Objective-C?

查看:64
本文介绍了如何在Objective-C中将大数相乘?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Objective-C中:

in Objective-C:

unsigned long t1 = 1310789847 * 1000;

导致溢出并显示错误的结果.

causes an overflow and shows an incorrect result.

我如何获得1310789847000?

推荐答案

使用NSDecimal.

Use NSDecimal. There are all sorts of handy functions in the Foundation framework for manipulating NSDecimal structs, which are basically super large numbers (not just integers). You get the basic operations of add, subtract, multiply, divide, exponentiate, etc, but those are usually powerful enough to do quite a bit of stuff.

这篇关于如何在Objective-C中将大数相乘?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆