Skip to content

Commit

Permalink
Generate doubles and floats over entire possible range.
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshRosen committed Jul 2, 2015
1 parent 5acdd5c commit b55875a
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@

package org.apache.spark.sql

import org.apache.spark.sql.types._
import java.lang.Double.longBitsToDouble
import java.lang.Float.intBitsToFloat

import scala.util.Random

import org.apache.spark.sql.types._

/**
* Random data generators for Spark SQL DataTypes. These generators do not generate uniformly random
* values; instead, they're biased to return "interesting" values (such as maximum / minimum values)
Expand Down Expand Up @@ -90,11 +93,11 @@ object RandomDataGenerator {
case BooleanType => Some(() => rand.nextBoolean())
case DateType => Some(() => new java.sql.Date(rand.nextInt(Int.MaxValue)))
case DoubleType => randomNumeric[Double](
rand, _.nextDouble(), Seq(Double.MinValue, Double.MinPositiveValue, Double.MaxValue,
Double.PositiveInfinity, Double.NegativeInfinity, Double.NaN, 0.0))
rand, r => longBitsToDouble(r.nextLong()), Seq(Double.MinValue, Double.MinPositiveValue,
Double.MaxValue, Double.PositiveInfinity, Double.NegativeInfinity, Double.NaN, 0.0))
case FloatType => randomNumeric[Float](
rand, _.nextFloat(), Seq(Float.MinValue, Float.MinPositiveValue, Float.MaxValue,
Float.PositiveInfinity, Float.NegativeInfinity, Float.NaN, 0.0f))
rand, r => intBitsToFloat(r.nextInt()), Seq(Float.MinValue, Float.MinPositiveValue,
Float.MaxValue, Float.PositiveInfinity, Float.NegativeInfinity, Float.NaN, 0.0f))
case ByteType => randomNumeric[Byte](
rand, _.nextInt().toByte, Seq(Byte.MinValue, Byte.MaxValue, 0.toByte))
case IntegerType => randomNumeric[Int](
Expand Down

0 comments on commit b55875a

Please sign in to comment.