Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

double 类型字符串在超过 NSDecimalNumber 最大值后转 Double 会造成溢出 #832

Open
wolfcon opened this issue Dec 29, 2021 · 0 comments
Labels
Milestone

Comments

@wolfcon
Copy link
Collaborator

wolfcon commented Dec 29, 2021

描述bug
double 类型字符串转 Double 会造成溢出

怎么样重现这个bug
Model

@interface MJDog : NSObject
@property (copy, nonatomic) NSString *nickName;
@property (assign, nonatomic) double salePrice;
@property (assign, nonatomic) float runSpeed;
@end

Test case:

func testInfiniteDouble() throws {
    let dict: [String: Any] = [
        "nick_name": "旺财",
        "sale_price": "\(Double.greatestFiniteMagnitude)",
        "run_speed": "\(Float.greatestFiniteMagnitude)",
        
    ]
    
    guard let dog = MJDog.mj_object(withKeyValues: dict) else {  fatalError("dog conversion failed") }
    
    XCTAssertEqual(dog.nickName, (dict["nick_name"] as! String))
    // 这个会通不过
    XCTAssertEqual(dog.salePrice, Double(dict["sale_price"] as! String))
    XCTAssertEqual(dog.runSpeed, Float(dict["run_speed"] as! String))
}
@wolfcon wolfcon added this to the 4.0.0 milestone Dec 29, 2021
@wolfcon wolfcon added the bug label Dec 29, 2021
@wolfcon wolfcon added this to To do in Refactor 4.0.0 Jan 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

No branches or pull requests

1 participant