Skip to content

Commit

Permalink
[flang] Address most review comments
Browse files Browse the repository at this point in the history
Original-commit: flang-compiler/f18@e616478
Reviewed-on: flang-compiler/f18#671
Tree-same-pre-rewrite: false
  • Loading branch information
klausler committed Aug 23, 2019
1 parent 79e8749 commit 787b997
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 36 deletions.
1 change: 1 addition & 0 deletions flang/lib/decimal/binary-floating-point.h
Expand Up @@ -67,6 +67,7 @@ template<int PRECISION> struct BinaryFloatingPointNumber {
BinaryFloatingPointNumber &&that) = default;

template<typename A> explicit constexpr BinaryFloatingPointNumber(A x) {
static_assert(sizeof raw == sizeof x);
std::memcpy(reinterpret_cast<void *>(&raw),
reinterpret_cast<const void *>(&x), sizeof raw);
}
Expand Down
68 changes: 34 additions & 34 deletions flang/lib/decimal/decimal.h
@@ -1,25 +1,26 @@
// Copyright (c) 2018-2019, NVIDIA CORPORATION. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// C and C++ API for binary-to/from-decimal conversion package.
/* Copyright (c) 2018-2019, NVIDIA CORPORATION. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/* C and C++ API for binary-to/from-decimal conversion package. */

#ifndef FORTRAN_DECIMAL_DECIMAL_H_
#define FORTRAN_DECIMAL_DECIMAL_H_

#include "binary-floating-point.h"
#include <stddef.h>

#ifdef __cplusplus
// Binary-to-decimal conversions (formatting) produce a sequence of decimal
// digit characters in a NUL-terminated user-supplied buffer that constitute
// a decimal fraction (or zero), accompanied by a decimal exponent that
Expand All @@ -30,9 +31,9 @@
// If the conversion can't fit in the user-supplied buffer, a null pointer
// is returned.

#ifdef __cplusplus
#include "binary-floating-point.h"
namespace Fortran::decimal {
#endif
#endif /* C++ */

enum ConversionResultFlags {
Exact = 0,
Expand Down Expand Up @@ -116,29 +117,28 @@ extern template ConversionToBinaryResult<112> ConvertToBinary<112>(
} // namespace Fortran::decimal
extern "C" {
#define NS(x) Fortran::decimal::x
#else
#else /* C++ */
#define NS(x) x
#endif /* C++ */

NS(ConversionToDecimalResult)
ConvertFloatToDecimal(char *, size_t, enum NS(DecimalConversionFlags),
int digits, enum NS(FortranRounding), float);
NS(ConversionToDecimalResult)
ConvertDoubleToDecimal(char *, size_t, enum NS(DecimalConversionFlags),
int digits, enum NS(FortranRounding), double);
struct NS(ConversionToDecimalResult)
ConvertFloatToDecimal(char *, size_t, enum NS(DecimalConversionFlags),
int digits, enum NS(FortranRounding), float);
struct NS(ConversionToDecimalResult)
ConvertDoubleToDecimal(char *, size_t, enum NS(DecimalConversionFlags),
int digits, enum NS(FortranRounding), double);
#if __x86_64__
NS(ConversionToDecimalResult)
ConvertLongDoubleToDecimal(char *, size_t, enum NS(DecimalConversionFlags),
int digits, enum NS(FortranRounding), long double);
struct NS(ConversionToDecimalResult)
ConvertLongDoubleToDecimal(char *, size_t, enum NS(DecimalConversionFlags),
int digits, enum NS(FortranRounding), long double);
#endif

NS(ConversionResultFlags)
ConvertDecimalToFloat(const char **, float *, enum NS(FortranRounding));
NS(ConversionResultFlags)
ConvertDecimalToDouble(const char **, double *, enum NS(FortranRounding));
enum NS(ConversionResultFlags)
ConvertDecimalToFloat(const char **, float *, enum NS(FortranRounding));
enum NS(ConversionResultFlags)
ConvertDecimalToDouble(const char **, double *, enum NS(FortranRounding));
#if __x86_64__
NS(ConversionResultFlags)
ConvertDecimalToLongDouble(
enum NS(ConversionResultFlags) ConvertDecimalToLongDouble(
const char **, long double *, enum NS(FortranRounding));
#endif
#undef NS
Expand Down
4 changes: 2 additions & 2 deletions flang/lib/evaluate/real.cc
Expand Up @@ -477,8 +477,8 @@ std::ostream &Real<W, P, IM>::AsFortran(std::ostream &o, int kind) const {
const auto *value{reinterpret_cast<const B *>(this)};
char buffer[24000]; // accommodate real*16
auto result{decimal::ConvertToDecimal<P>(buffer, sizeof buffer,
static_cast<decimal::DecimalConversionFlags>(0), 999999,
decimal::RoundNearest, *value)};
static_cast<decimal::DecimalConversionFlags>(0),
static_cast<int>(sizeof buffer), decimal::RoundNearest, *value)};
const char *p{result.str};
if (DEREF(p) == '-' || *p == '+') {
o << *p++;
Expand Down

0 comments on commit 787b997

Please sign in to comment.