Skip to content

Instantly share code, notes, and snippets.

@MasazI
Created May 29, 2015 10:21
Show Gist options
  • Save MasazI/60027def3f12fbcc2d90 to your computer and use it in GitHub Desktop.
Save MasazI/60027def3f12fbcc2d90 to your computer and use it in GitHub Desktop.
numeric_limits.cpp
//
// limits.cpp
// CplusplusPractice
//
// Created by masai on 2015/05/19.
// Copyright (c) 2015年 masai. All rights reserved.
//
#include <iostream>
#include <limits>
typedef long HashValueLong;
typedef unsigned long HashValueULong;
int main() {
// マクロ定義による取得
std::cout << "int max: " << INT_MAX << std::endl;
std::cout << "int min: " << INT_MIN << std::endl;
// クラステンプレートによる取得
std::cout << "int max: " << std::numeric_limits<int>::max() << std::endl; //2147483647
std::cout << "long max: " << std::numeric_limits<long>::max() << std::endl; //2147483647
std::cout << "long min: " << std::numeric_limits<long>::min() << std::endl;
std::cout << "long lowest: " << std::numeric_limits<long>::lowest() << std::endl;
std::cout << "double max: " << std::numeric_limits<double>::max() << std::endl;
std::cout << "double min: " << std::numeric_limits<double>::min() << std::endl;
std::cout << "double lowest: " << std::numeric_limits<double>::lowest() << std::endl;
// 型に依存しない書き方
std::cout << "HashValue(long): " << std::numeric_limits<HashValueLong>::max() << std::endl;
std::cout << "HashValue(unsigned long): " << std::numeric_limits<HashValueULong>::max() << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment